Every computer in any TCP/IP network … like the Internet, or the network in your home … has an IP-address. The address is, no doubt, a set of 4 numbers (each one in the range 0-255… that is to say, four bytes).
There are a few “special” addresses: - 127.0.0.1 always refers to “this box.” It goes by the name “localhost,” or is sometimes called a “loopback.” - Addresses such as “192.168.xxx.xxx” are called non-routable addresses. That is, they always refer to “this network.” The addresses of the various items within your home-network will be like this. (There are several designated groups of “non-routable addresses” to choose from…)
Your entire house has only one IP-address, though, as far as the Internet-at-large is concerned. That address is held by, and known only to, your “router.” What the router does, then, is to distribute inbound and outbound traffic between “the Internet” and “your home network.” (They are, and they remain, two separate networks. Your router serves as the so-called gateway between them.)
If you want to game within your home, it’s easy: the IP-addresses are unique and they are confined to your home.
If you want to game with your neighbor, however, the traffic will have to go through two routers… yours, and your neighbor’s. The trick is, you won’t see the IP-addresses within your neighbor’s network. Instead, the traffic will come from the (Internet…) IP-address of your neighbor’s router, and a particular port-number, which is rather like a telephone “extension.” (Port-numbers are assigned by the router, and they are actually “how routers know how to distribute the traffic.”)
In a small game, the computers can talk directly to one another … so-called peer-to-peer. But as the number of players increases, it becomes more efficient to route all the traffic to a central server, a so-called socket server, whose job is to maintain the state of the game and to send-and-receive appropriate notification messages from the players. In effect, the socket-server(s) “run” the game, while the individual client-computers manage the drawing of what you see.
There are many commercial socket-servers, but there are open-source ones too. The programming required to implement such a server is both “not trivial” and “highly repetitive,” since it is the necessary-foundation upon which the game-specific logic is based. That’s why you usually see games being constructed around such a foundation, and maintained by vendors who license them for their profit.