Take the 2-minute tour ×

I have a question concerning communication between a server and a client using UDP. I'll first explain what I'm trying to do.

  • The client sends a message to the server using a random UDP source port to a static server UDP port (11000).
  • The server then learns the clients sending port.
  • Then the server sends a message back to the client using another random port to the clients sending port.

The problem is that the server can only send back if clients random port is forwarded on the router. I don't know if it's possible but shouldn't the server be able to send back to the the client using the same port the client used to send without forwarding the port? I also read about hole punching but if I understand correctly it's only needed when you want peer-to-peer connection. The server had a static ip. I'm trying this in C#.

I hope the question is clear. Thanks in advance!

EDIT: Information about the setup:

The client is a game client which should be able to connect to the server from almost any location. (It's currently running on my home pc). The server is located at school and has a static IP. All ports on the server are open and the server is also used for ftp and has a server running that uses TCP. Those things work fine. TCP works because it creates a connection and the server uses that connection to send back to the client. The problem with UDP is that the server can't send back to the client because UDP is connectionless.

Like I said if I open ports on the client everything works great. But my question is: How do I send back to the client without opening ports on the client? Most games don't require you to open ports. So is there any possibility to either send back without port forwarding or can I open a port using C#?

EDIT2: Found the answer

I found the answer. To communicate you need to use the same UdpClient to both send and receive. I was using one to send and one to receive.


share|improve this question
Can you please be more precise on the setup? Where is the server located? At your end? Clients are coming in from the Internet? Is there a firewall in place in front of the server? Why do you use random ports? –  Living Skull May 20 '13 at 12:37

Your Answer



Browse other questions tagged or ask your own question.