In lots of multiplayer games there is the option for LAN play. My question though is how does a client know where a server is on the LAN?

The only ways I can think of

  1. Send out broadcasts over the broadcast address. This has the disadvantage of being filtered sometimes by routers or switches in different network environments.
  2. Attempt to connect to a server on every IP in your subnet. This has the disadvantage of being slow (Especially if the network uses 10.XXX.XXX.XXX for their IPs) and a mini ddos attack, but isn't going to be filtered.

How do games do this especially in other network environments?


1 Answer 1


For games with LAN play, the standard thing to do is for the clients to send broadcast packets to discover servers. (The client sends a broadcast, the server sends a direct reply to the client)

In general, the client will send somewhere between three and five broadcast messages, each about a second apart, and will then decide that there must be no server if it hasn't heard any reply within that time. Sending multiple packets makes service discovery a little more packet-loss-tolerant (though that is pretty uncommon on LANs), and having time between them keeps them from disrupting other network traffic too much.

Nobody (to my knowledge) does your option #2, because it will degrade performance of the LAN (or will take quite a while, if you stagger the connection attempts).

But to cope with cases where broadcast is filtered by the local LAN (which is quite unusual, but not unheard-of), most games will allow players to directly enter an IP address to connect to. This allows players in these sorts of situations to connect to a known server, even it they can't broadcast to automatically find it.

For games over the internet, clients will send a direct request to a static meta server, which replies with the addresses for known current server instances. Servers, likewise, contact that meta server to inform them of their own location so that clients can be directed to them. Due to the complexities of NAT, though, this approach usually does not work for servers hosted inside a LAN. This is why this sort of approach is not typically used for LAN games.

Extra side note: It's common practice for internet games to contact a point server first. The point server tells the game on what address it can find the meta server, which will tell it where servers can be found. Point servers are often (though certainly not always) implemented as a simple web server, and are the only piece of this system with an address that is hardcoded into the game. This allows game developers to move their meta server around from one machine to another as required, simply by updating the address returned by the point server. It can also be used to implement a simple form of load-balancing or region-switching by having the point server send users to different meta servers based upon server load or geographical proximity.

  • 2
    \$\begingroup\$ +1 to you sir, this answered a few questions I had as well. \$\endgroup\$
    – raine
    Jun 9, 2011 at 22:34
  • 2
    \$\begingroup\$ +1, Broadcast is the way to go as it actually IS the proper way to do #2, hehe.. That is what broadcasting is for, contacting multiple IPs to see if anything is listening. \$\endgroup\$
    – James
    Jun 9, 2011 at 22:57
  • \$\begingroup\$ Yeah, the only problem with broadcast is certain (large corporate, in particular) LANs which don't propagate broadcast between all LAN segments. In the future, multicast will presumably be the new way to do this, and should automatically work across all LAN segments. But right now, proper router support for multicast is still too spotty to rely on as a replacement for broadcast. Give it another few years and things may finally improve. \$\endgroup\$ Jun 9, 2011 at 23:54
  • \$\begingroup\$ The few times I've come across corporate networks that don't support broadcast, I've found all sorts of other routing problems going on that are usually caused by defective equipment (sometimes fixed by upgrading the router's firmware). If broadcast isn't working in a local LAN segment, then it's unlikely to be intentional. \$\endgroup\$ Jun 10, 2011 at 1:36

You must log in to answer this question.

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