Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Appending two packets together  (Read 3204 times)

0 Members and 1 Guest are viewing this topic.

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Appending two packets together
« on: September 13, 2013, 01:47:40 pm »
Is it possible to append two packets together?
Code: [Select]
// the first packet
sf::Packet packet1;
packet1 << std::string("eat") << std::string("IceCream");

// the second packet
sf::Packet packet2;
packet2 << std::string("run") << FORWARD_RUN;

// the two above packets appended would be read like
sf::Packet packet1plus2;
std::string cmd1, cmd2, item;
int runDir;
packet1plus2 >> cmd1 >> item >> cmd2 >> runDir;

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Appending two packets together
« Reply #1 on: September 13, 2013, 02:03:05 pm »
packet1plus2 = packet1;
packet1plus2.append( packet2.getData(), packet2.getDataSize() );
 
This is easy to figure out if you read the API documentation on sf::Packet...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Re: Appending two packets together
« Reply #2 on: September 13, 2013, 05:16:13 pm »
That was not obvious to me unfortunately. Thank you for the help!

I thought the data included some type of header too (specific to the packet), but I guess not.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Appending two packets together
« Reply #3 on: September 13, 2013, 05:21:45 pm »
sf::Packet is just a glorified std::deque that provides stream-like access. The header that is generated when sending the packet is completely done within the corresponding socket class.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).