Recently I had to write a LAN game server/client for C-Dogs SDL. I was surprised at how little information was available, so I thought I might document my solution here.
The Problem: Which IP to connect to?
Most people who have made, or attempted to make, network-multiplayer games will know that there are two ways to get two game instances to connect to each other:
- Directly, by entering the IP address of the other game instance, or
- Using an online “server list”, which is basically a list of IP addresses constantly updated
Most “game server browsers” actually download lists from several known locations, a fancy way of doing no. 2. But no. 2 boils down to picking an IP from a list, which the game then uses to connect to directly anyway - no. 1. The point is: to connect two games, you need the IP address.
In ages past there were dial-up modems where you could connect using phone numbers, or IPX which is similar to IP but has different addresses. The protocols have changed but the problem is the same.
But how do games see each other on a LAN? Somehow many LAN-enabled games can scan and find servers running on a LAN, and avoid having to enter IP addresses manually. They also do this without having to access a remote server list.
Read more