SFML community forums
Help => Network => Topic started by: Merle on June 04, 2018, 09:59:56 pm
-
I made a pong game which works across LAN, and then I realized it might be possible to move it to across the internet, but I didn't know how to. Here are some simple questions I have about it.
Do I need to port forward? If I do need to, how do some games not require you to port forward to be able to play with one of your friends?
Do I need to change any of my actual code? Are there any settings/conditions that aren't enabled by default in each program that need to be met in order to work across the internet?
Thank you.
-
Are you using UDP or TCP for networking?
Ports are required to be open to connect from one PC to another outside of the network; however, you can get around the manual process of opening these ports (port forwarding) by performing a hole-punch which will temporarily open the ports desired.
TCP hole-punch: https://en.wikipedia.org/wiki/TCP_hole_punching (https://en.wikipedia.org/wiki/TCP_hole_punching)
UDP hole-punch: https://en.wikipedia.org/wiki/UDP_hole_punching (https://en.wikipedia.org/wiki/UDP_hole_punching)
Most games do not require you to port forward by using a central server (that already has its ports open) to either:
- Inform the game host of an in-coming connection from the IP address: xxx and port: yyy. Both the server and client begin conveying messages to one another to temporarily open their ports (see hole-punching links above).
- Use the central server to sync game data.
As for your last question regarding changes to your actual code; you may possibly run into latency issues depending on how you've implemented syncing data, as a LAN connection has little to no latency in comparison to a connection outside of the network.
-
I'm using TCP, thanks for responding. I'll look into hole punching, I was always curious how I could play certain games with friends with little to no setup.
-
I'm a bit confused about it, so you have both clients connect to a server with different sockets, and then send connection info over it? But this is TCP, do you need a UDP socket for this to work?
-
It is quite an advanced topic. Unfortunately, TCP hole-punching is by far the most complicated. TCP hole-punch generally involves both parties to perform a series of connection attempts that have the intent to fail but result in leaving the desired ports open.
Generally a third server is involved to help co-ordinate these connections.