Jump to content
  • Advertisement
Sign in to follow this  
Striken

Beginner Q.: UDP Testing

This topic is 4316 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 all, quick & simple question straight to the point. Can anyone give me an example of how they've set up test and debug UDP Client / Server set up on their local machine? ----- I currently have this set up. Client program 2 datagram sockets, (1x send, 1x receive - just for easy understanding) Server program 2 datagram sockets, (1x send, 1x receive - just for easy understanding) ----- The problem is that I've bound the server "receive" socket to listen on a particular address & port, so I can send packets FROM the client to the server. However, because this port is bound to the server's receive socket, if I try and bind the client's "receive" socket to the same address, it fails with the WSA error that it's already in use essentially (error code 10048L if i recall correctly). Any suggestions? Am I doing this completely wrong - apologies I am very new to this all :) Also curious as to how you guys test your simple applications at home - have you bought a hosted server and run (client or server) remotely when you debug? thx !

Share this post


Link to post
Share on other sites
Advertisement
Just use loopback as the address for the packets(127.0.0.1) and assign the servers to different ports. The only thing you need to make sure is that the port is not used by anything else.(simply called a well known port) Try high numbered ports as the are usually free.

Share this post


Link to post
Share on other sites
Quote:
2 datagram sockets, (1x send, 1x receive - just for easy understanding)


That's a terrible idea! It means you are not NAT safe.

You should use one socket on the client, and one socket on the server. You should bind the server to a known port, and let the client bind to whatever port the IP stack chooses.

You should use recvfrom() on the server, and sendto() to send data back to the address you got in recvfrom().

When you do this, running client and server on the same machine will work fine, either using the local machine's IP address (which might be a private address like 192.168.... or 10....), or the loopback address (127.0.0.1).

This is the absolutely easiest way to implement a UDP client/server -- more sockets just makes it harder in addition to breaking NAT traversal.

Share this post


Link to post
Share on other sites
aah! thanks for the help guys!

I was blindly ignorant to that fact about using two sockets, I just thought it would make it easier for me to understand.

Is there no concept of thread safety with using a single socket though? What happens if I try to send and receive from a socket at the same time?

Share this post


Link to post
Share on other sites
Depends on the OS. Linux, BSD and WinSock 2.2 should deal fine with that. Make sure you pass version 2,2 to WSAStartup().

Share this post


Link to post
Share on other sites
thanks for the help :) i've got my client / server sending and receiving reliable / acknowledgement packets nicely! how very satisfying

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.

GameDev.net 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!