Handling packets (C++)

Results 1 to 4 of 4
  1. #1
    Apprentice teunxd is offline
    MemberRank
    Oct 2013 Join Date
    13Posts

    Handling packets (C++)

    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: https://github.com/Pitten/Ladybug/bl...erver/main.cpp


    Thanks.


  2. #2
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,608Posts

    Re: Handling packets (C++)

    Header is 2 bytes starting at index 4.

  3. #3
    Apprentice teunxd is offline
    MemberRank
    Oct 2013 Join Date
    13Posts

    Re: Handling packets (C++)

    Quote Originally Posted by The General View Post
    Header is 2 bytes starting at index 4.
    Thanks! Got it now. :)

  4. #4
    Apprentice sirjonasxx is offline
    MemberRank
    Sep 2014 Join Date
    BelgiumLocation
    19Posts

    Re: Handling packets (C++)

    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.



Advertisement