SFML community forums

Help => Network => Topic started by: Wizzard on September 13, 2013, 01:47:40 pm

Title: Appending two packets together
Post by: Wizzard 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;
Title: Re: Appending two packets together
Post by: binary1248 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...
Title: Re: Appending two packets together
Post by: Wizzard 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.
Title: Re: Appending two packets together
Post by: binary1248 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.