I wouldnt say that creating network code is too hard, I havent tested mine yet under extreme conditions with like 500 people connected, but that time is almost here =).

I basically have (client side) 3 threads for my MMORPG. One in , one out thread, one graphics and sound thread, one client side predictions thread.


all messages have a Start Character (one for server one for client) so the other end knows its a real message, then a message ID, then a Message Length. I send binary messages to save some space, so I have to use length to find the end of the message in the stream of characters.

The In and Out threads do there job like this.

Out has a que of messages, Message packager classes take what the client needs to send to the server puts it into a string with minimal compression (like using characters for numbers 1-255) and attaches it to the out threads send que.

In thread has a list of message handler classes with their message's ID it reads the first couple characters to fill the header, finds the length, reads the rest, and passes it to the appropriate Message Handler class to be parsed and use on the client side database moving people's characters or changing the clients character in some way.

The Graphics thread runs in a circle just rendering what the client database has. The client side predictions thread handles moving characters client side along their know paths to hide the latency.

This whole process allows me to simply create a new class for a message and not have to edit the actual network code! But its also for an RPG...

PS. I use TCP