I'm working on a TCP turn multiplayer game.

I've read many tutorials and stuff, and they all said to use Async IO, but, none of than give practical examples on how to do it.

I was thinking that in every TCP data stream sent, the client would have to send who is he, and what he's doing. Is it really necessary? What's the best way to deal with host identifying? If I should deal with this at all...

Should I check in every message if he's who he's claiming to be? There's any comprehensive game packet analysis avaiable on the web? I think I would learn much from this kind of source.

EDIT: I'm doing a server/many-clients model.

Thanks, Julio Rodrigues

  • \$\begingroup\$ "Should I check in every message if he's who he's claiming to be?" - There's no real way to do that, any method you use can be circumvented by an able hacker. You can only make it harder. \$\endgroup\$ – John McDonald Aug 25 '11 at 15:57

Let me try answering that from positions of RTS (think of it as TBS where each turn is 100msec).

There is separate thread for receiving and sending messages, it has it's own buffer and is black-box to the rest of the game (the game should know nothing about protocol and format). The game sends commands to networking unit and receives complete commands as they are available and verified to be complete.

When networking unit receives a new message it appends it to buffer and checks if buffer has a complete command. That is why each message has a header specifying contents length and CRC. That is ASync part of it.

How to identify the host? That depends on your network layout, is peer-to-peer or centralized server or .. ? If you trust your clients to do the computations (not advised for serious gaming) then there's no host at all, Everyone trusts everyone to supply valid data. If you have a separate host (could be running as stand-alone task on one of players machines) - it does all the computations and clients act as terminals, doing only View-Controller roles.


We use TCP module from OverbyteICS (that is one more layer between the networking module and Net) and it does it for us, each time new connection is made it is assigned new "stream". So when message arrives we know the "stream" who sent it, but in networking module we keep remap table, so that in lobby all players have UIDs and in game all players are IDs 1..8 (again, game knows nothing about networking UIDs).

As for specific details I can't say how it's made inside OverbyteICS, but we have possibility to launch local server and 1-8 clients on the same PC (all having same IP and they are all distinct in game, so this means OverbyteICS takes care of that.

| improve this answer | |
  • 3
    \$\begingroup\$ +1 "the game should know nothing about protocol and format" \$\endgroup\$ – John McDonald Aug 25 '11 at 15:52
  • \$\begingroup\$ The thing is, with Async IO, and with players with the same IP I need to have a way to uniquely indentify them, right? I was reading that I need to make a Game Network Protcol, even a if it's simple one, does this make sense to you? \$\endgroup\$ – user9471 Aug 25 '11 at 16:22
  • \$\begingroup\$ Thank you for the explanations, I'm doing something like this. \$\endgroup\$ – user9471 Aug 27 '11 at 4:07

This isn't necessarily an answer, but whenever I have network architecture questions, I refer to this wonderful document about how Unreal Engine does it:


It's way more than you need, but it's a great read and you'll likely be able to use concepts from it.

| improve this answer | |
  • 1
    \$\begingroup\$ I'm reading it, seems to be very useful! \$\endgroup\$ – user9471 Aug 25 '11 at 16:20

Async IO is just a general term for handling input and output. How to actually implement that depends entirely on the platform and language you're using. Usually the result is that you just set up a connection and then you have callbacks which get called when data arrives on the connection.

I was thinking that in every TCP data stream sent, the client would have to send who is he, and what he's doing. Is it really necessary?

No, it's not necessary. TCP is a connection based protocol, between 2 end-points. For as long as the connection is up, you know it's the same person on the other end, so they only need to identify themselves once.

What's the best way to deal with host identifying?

You can get the host's IP address and port from the network API you use, when connected. Again, how to do this depends on the API. A remote IP address and port pair is a unique identifier for incoming TCP connections.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy