0
\$\begingroup\$

So, lets say i have a client and server sending information to each other. Do i have to port forward both the server and the client, or do i just port forward the server? If i have to do both, is there any way of not needing to port forward? Im using SFML to be specific.

This isnt on local networks and its using UDP.

\$\endgroup\$
1
\$\begingroup\$

No, you don't need to port forward the client. If the server runs on a home computer (behind a NAT) then yes, you need to port-forward the server or check out how udp-hole-punching works but if the server runs on a real server (a server you rent with a public ip-address) then it should work out of the box.

Note though, the client, which is probably behind a nat, needs to send the first (and possibly a few more) UDP-packets to the server before the server can reach the client.

Another thing to note: It doesn't matter on which port the client listens for UDP-packets (and on which port it sends), the server has to send it's packets back to the port which the receiving packets contain as sender-port, which is not necessarily the port the client listens on!

For example:

The client listens on port 5555 and therefore sends its packets from port 5555. The server also listens on port 5555 and sends its packets from port 5555. The client now sends a packet to the server to port 5555 but the server sees the packet coming from client_ip:45671. The server now needs to answer to port client_ip:45671, not to client_ip:5555 even though the client listens on port 5555!

\$\endgroup\$
  • \$\begingroup\$ I didnt quite understand the last part \$\endgroup\$ – user68817 Feb 1 '16 at 10:03
  • \$\begingroup\$ @JFrap added a simple example, hope this clarifies it. \$\endgroup\$ – tkausl Feb 1 '16 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy