Online Gaming – How Does an Online Game Continue After the Host Leaves

networking

Note: This is a question about networking, not gaming. I'm using StarCraft merely as an example.

The game StarCraft (not StarCraft 2) supports online play. One person hosts, and other people join. If the host leaves during the game, the game can continue indefinitely without the host. How does that work?

Consider the following scenario:

  • I host a 3 versus 3. Note that, for people to be able to join, my router has to be configured to port forward 6112, TCP and UDP (see Blizzard Support).
  • Five people join. Everyone (myself included) is behind a router. I start the game.
  • Three minutes into the game, about twenty zealots pour into my base. Nobody helps me.
  • My base is eliminated, so I leave (the game doesn't give you a choice).
  • The game continues without the host (the home team has two players left).

How do the remaining five clients (who didn't need 6112 forwarded) remain connected?

If I understand correctly: if two programs want to talk to each other, one of them has to be a "server" and listen for connections on a port, while the other has to be a "client" and initiate a connection request on that port. They can't simply start sending packets to each other (and I don't even know how they would, if both are behind routers).

Someone hosting a game is a server, while those joining it are clients. It's easy to see how the clients can start communicating with the server. What I don't get is: how do the clients start communicating with each other without going through the server? Does the Internet Protocol allow a server to initiate connections between clients?

It's entirely possible that, in the case of StarCraft, game traffic goes through Battle.net servers. StarCraft does maintain a connection to Battle.net during games (for messages from friends, etc.). However, I doubt game traffic goes through it, because if it did, why would hosts need to port forward 6112?

My question is: can a server, with multiple clients connected to it, initiate connections between them?

Best Answer

That sounds like UDP hole punching

Let A and B be the two hosts, each in its own private network; N1 and N2 are the two NAT devices; S is a public server with a well-known globally reachable IP address.

  1. A and B each begin a UDP conversation with S; the NAT devices N1 and N2 create UDP translation states and assign temporary external port numbers
  2. S relays these port numbers back to A and B
  3. A and B contact each others' NAT devices directly on the translated ports; the NAT devices use the previously created translation states and send the packets to A and B

In this example, you are S. Your opponents are A and B. When you are kicked from the game, your opponents can continue playing because they had negotiated a connection to each other when they first connected to you.

Related Topic