If you know that performing
action A + action B = C
You can reduce network traffic by transmitting only what is necessary. In the context of a game consider this:
It's called naggle's algorithm and it's already there by default, but we usually like to deactivate it because it increases lag.
Use the flag TCP_NODELAY to remove it.
My actual server is about 25 000 lines but this includes the game logic with CUDA, the physic, the anti hack, the packet handling, the encryption...
It's kinda big but totally worth it, what's better than a server that can't crash because there is a fall back system for every error possible, unhackable well at least uncrashable :p . It's fast. easy to modify since everything is completly automatic, if I want to add an opcode I have to add 4 lines of code.
Code: Select all
__function[SMSG_NEWOPCODE] = &WorldSession::HandleNewOpcode;
and
void WorldSession::HandleNewOpcode(WorldPacket& packet)
{
_world.broadcast(CMSG_CHAT,ChatPacket("New Opcode received !"),TCP);
}[/code]
Networking is annoying if you are not making a framework based on the system API, if you keep the API you will struggle with the data, endianess... but if you make a easy to use framework which takes care of serialization, packet handling, client handling... it's really easy and you will be proud of your system ^^ .
So before doing actual networking make a framework, you will see how fast you will be going once you are done with your framework.
But again networking ain't something you can master after reading one tutorial, it takes a long time and a lot of practice/theory.