Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 robert_j_porter   Members   -  Reputation: 119

Like
0Likes
Like

Posted 08 March 2014 - 12:29 PM

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, 08 March 2014 - 12:30 PM.


Sponsor:

#2 Scourage   Members   -  Reputation: 740

Like
0Likes
Like

Posted 08 March 2014 - 03:58 PM

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.

 

Cheers, 

 

Bob



Halfway down the trail to Hell...

#3 3TATUK2   Members   -  Reputation: 730

Like
2Likes
Like

Posted 09 March 2014 - 04:58 PM

http://enet.bespin.org/

 

/thread



#4 hplus0603   Moderators   -  Reputation: 5309

Like
0Likes
Like

Posted 09 March 2014 - 09:48 PM

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.
enum Bool { True, False, FileNotFound };




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS