4
\$\begingroup\$

I already know how to write games in C#, and I've learned the concepts behind network game programming, and created a working multiplayer game that works over LAN.

As an example, somebody runs the game server, which keeps track of the position of... say, a ball. Every so often, the server sends the current location and velocity of the ball to each of the connected clients. If something goes prevents the server from sending the stuff to the clients, the clients can still calculate the position of the ball by using the velocity, and hopefully stay closely enough synchronized with the server until it can resume sending again.

This is all very well and easy over LAN... but how do the clients connect to the server over the internet?

\$\endgroup\$
2
  • 4
    \$\begingroup\$ Doesn't your LAN also run on IP (the Internet Protocol)? What's the difference? (except some extra latency, which you already seem to know about) \$\endgroup\$
    – Matti Virkkunen
    Commented Jun 30, 2011 at 20:18
  • \$\begingroup\$ I have no idea... I'm pretty new to network programming \$\endgroup\$
    – Entity
    Commented Jun 30, 2011 at 20:20

2 Answers 2

5
\$\begingroup\$

In exactly the same way as on the LAN. They report to the gameserver. If necessary, you can set up a centralized directory server that contains IP addresses and other relevant information about the game servers. From then on, it is exactly the same as on a LAN, where you probably ran over TCP/IP too.

\$\endgroup\$
2
  • \$\begingroup\$ Is that really it? I read that you have to host some sort of web server that the clients connect to, and it forwards whatever they send to it to the game server, and vice verca... \$\endgroup\$
    – Entity
    Commented Jun 30, 2011 at 20:31
  • \$\begingroup\$ @TheAdamGaskins: That web server is just a computer the gameserver software runs on. The forwarding is just a matter of network configuration to make sure the TCP or UDP packets actually get through. \$\endgroup\$ Commented Jul 3, 2011 at 9:17
2
\$\begingroup\$

The same way any internet app connects to any server over the internet. The client needs (either hard coded or in a config file or wherever) either a static IP address or a DNS hostname that will resolve into the server's (or the server's network border router's) IP address. You also have to make sure the ports you're using are forwarded through your router and opened in your various firewalls so the packets can get through.

If you don't have a static IP, you can use a service like DynDNS to dynamically update a hostname to point to your dynamic IP. I've used them for years and never had an issue.

For a gaming-related example, I run a TeamSpeak3 server at home. When I'm connecting to it over the LAN from my personal machine I don't need to do anything but enter the port and local IP. To connect from the public internet, I have to set up DynDNS to keep my hostname pointing to my dynamic IP and set up port forwarding on my router to forward the TS3 ports to my local server machine.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .