Search code examples
network-programmingtcptcpclient

Network and portforwarding TCP, UDP


How would one go about setting up a server and a client using TCP or UDP without the need of portforwarding on the client side?

A general scenario between a server and a client, say you made a simple game and you wanted them to be able to talk to each other without the need for portforwarding especially on the client side. (Client as usual behind firewall and router like a typical/user gamer would be)


Solution

  • Let's take sample setup. Your server is behind router/firewall, so it has no public IP-address and could not accept connections directly. By this reason you make your router (which has public IP-address) to forward some port (i.e. data from incoming connections to some of its ports from big Internet) to some port of your server. The only requirement for the client is to be able to reach router's public IP. Just like any other Internet-address.

    P.S. Your router is better to have static IP-address in big Internet, so the clients could find it easily.