Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jul 3 '11 at 8:41

This question came from our site for professional and enthusiast programmers.

4  
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) –  Matti Virkkunen Jun 30 '11 at 20:18
    
I have no idea... I'm pretty new to network programming –  TheAdamGaskins Jun 30 '11 at 20:20
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
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... –  TheAdamGaskins Jun 30 '11 at 20:31
    
@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. –  Jonathan Hobbs Jul 3 '11 at 9:17
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.