Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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