• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Handling packets (C++)

Newbie Spellweaver
Joined
Oct 25, 2013
Messages
13
Reaction score
0
Hello,

For education purposes I am writing a C++ Habbo Server from scratch by using the sys/socket library for sockets and mySQL for database.

I already got a socket running and the way of returning messages (thanks to github/Icarus-cpp).

However, now I want to handle the incoming packets.

The way I am wanting to do is creating a map, inserting in the map the header + event, and getting the elements from it by using "count".

I already got a demo of that working, but now the problem is how I can get the header packets from the incoming messages, without using boosts for example.

So, in main.cpp I can handle a header by using clientmessage.checkHeader(sizeof(buf));
Code is here:


Thanks.
 
Newbie Spellweaver
Joined
Sep 27, 2014
Messages
19
Reaction score
4
Might be important to note that multiple packets can be send in one TCP packet, so the header will not always start at index 4.
You should check the length of the whole TCP packet and then read the first 4 bytes, which will tell you how long the real "packet" as we know it is, if this doesnt make sense with the TCP data length you will most likely have to redo the process at the point where the first packet ends, to read a second packet.

The opposite can also occur, that one packet is spreaded over multiple TCP packets.
 
Upvote 0
Back
Top