Advertisement Jump to content
Sign in to follow this  

reliable UDP(I'm going in circles...)

This topic is 1774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I'm trying to have 2 players on a LAN find each other so that they can play a LAN game together. So I am broadcasting UDP, but I'm going around in circles trying to make it reliable. Sorry if my logic is a little confusing, let me know if something isn't clear. It's not 100% clear to me, hence the question. I'm sort of new to network programming, so I think I'm just missing something basic.


My algorithm that I have come up with is something like:


When a network game is started, continuously broadcast a search message at a regular interval. the search message contains the IP address of the sender.


At the same time listen for the opponents search broadcast.


Also listen for the opponents ACK message.  


When a search broadcast is received, send ACK messages until an ACK-ACK is received.


When I receive a ACK message, I can stop the search broadcast and send back an ACK-ACK.


Now my problem is how do I know when the opponent has received the ACK-ACK? The opponent can't stop sending ACKs until they receive the ACK-ACK, since they don't know if I've gotten the ACK yet. Obviously making a chain of ACK-ACK-ACK-... messages isn't going to work. If I am just on a Lan, everything should be pretty reliable, so should I just send 2 or 3 ACK-ACK messages a little spaced out, sleep for a second before I start the game, and assume that they got them, and just fail when I get a socket error later or something?


I think I'm just going to change my code to broadcast a UDP search message and send and listen for a TCP ACK. This way my problem is kind of solved. But really I'm just curious as to why I can't seem to figure out reliable UDP.  

Edited by robert_j_porter

Share this post

Link to post
Share on other sites

So I think a reliable UDP implementation is a little bit of overkill here, and developing a new one is pretty hard.  I think the confusion you are having is due to mixing a couple of concepts: finding each other and connecting.  Why don't you setup the broadcast to broadcast a UDP message with the ip address of the sender and it's port that it's listening on for data, which is a different port than what they are broadcasting on.  Then in the other machines, when they get this "beacon" message they know there is somebody out there that they need to send data to and just keep a list of peer applications to send data to, no need to really "connect."  If you want reliable, you could use the UDP broadcast to beacon the server and then use TCP to connect clients to the server on the ip/port that the server put in the beacon message.  


My overall advice is to get something working, even if it's TCP and then address it IF it becomes a bottleneck.


Again, this all only will work on a LAN because UDP broadcast typically doesn't get past routers.





Share this post

Link to post
Share on other sites
You really don't need "ack" and "ack-ack" to be separate packets. At the point where you get an "ack" from the other end, you know that the other end knows about you. Thus, just wait on either end until you get an ack from the other end. Tie the other ends together using a hash table based on IP address and port. If you receive a "solicit" from an IP:PORT that you already have received an ACK from, then just send another ACK.

Also, if "hosting/serving" is separate from "joining," it's usually better to have each new player send a broadcast once a second, and have the servers listen for broadcasts and reply with "I'm a server" messages, than the other way around. That way, a server that's started and stays up, won't use network bandwidth when nobody wants to join it.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!