Jump to content
  • Advertisement
Sign in to follow this  
sipickles

UDP help

This topic is 3540 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

Hi, Just a quick question. Is there any way to do a server->client send using UDP? I am using TCP for all my networking at present, but would like to shift some frequent message types to UDP. I've seen examples where a UDP server replies to a client request, but since UDP is connectionless, I am not sure the server can initiate a message. How about if the client has first made contact with the UDP server? Can the server keep the UDP connection open then? I am using Boost::Asio for my networking Thanks Simon

Share this post


Link to post
Share on other sites
Advertisement
I still fairly new to networking so take what I say with a grain of salt.

Quote:
Is there any way to do a server->client send using UDP?

-Yes

Quote:
I am using TCP for all my networking at present, but would like to shift some frequent message types to UDP. I've seen examples where a UDP server replies to a client request, but since UDP is connectionless, I am not sure the server can initiate a message.

-No the server cannot make first contact with the client.

Quote:
How about if the client has first made contact with the UDP server?

-With UDP the client must first make contact with the server. The way they 'talk' to each other is by sending each message to a certain IP address.

Quote:
Can the server keep the UDP connection open then?

- Well, like you stated it is a connectionless communication. If you want to have the server send stuff to the client without it only being a response to a message the client sends you must store it's IP address.


You mention that you want to change some frequent messages to UDP. Is it important for the messages to arrive at all? A downfall of UDP is that it doesn't check if the packets have arrived in order, or if they have arrived at all like TCP. You can make UDP act like it with the use of ACK's.

Share this post


Link to post
Share on other sites
If the client is behind a NAT (router), then it's very difficult (impossible?) to get the server to send the first packet to the client. Because the client's router could have 2 or more machines behind it, when the packet from the server arrives, the router doesn't know what to do with it, so it'll discard it. If you have the specific UDP port forwarded on the router then the packet can be sent to the correct machine, but that requires every single user if your app to have access to their router (Which isn't usually possible in places of work and universities, etc), and knows how to configure it.

The best thing to do is to have the server waiting on UDP packets on a specific port. When the server gets a packet from the client, it can then reply with a packet, so long as it replies using the same port.
The client's router will notice the packet going out to the server and note what client PC it came from, so when it gets a packet from the same IP:port as that packet was sent to, it can forward it on to the correct client and the client receives the packet.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!