SFML community forums

Help => Network => Topic started by: Veeper on September 08, 2014, 08:41:18 pm

Title: Difference in sending small and big packets.
Post by: Veeper on September 08, 2014, 08:41:18 pm
Hello guys. Just wanted to ask if there's a significant difference in speed between sending packet like this one:
packet << "movement" << "moveRight" << "moveLeft" < "blablablabla";
and this one:
packet << 1 << 2 << 3 << 4;

Thanks for response!  ;D
Title: Re: Difference in sending small and big packets.
Post by: Geheim on September 08, 2014, 08:53:51 pm
Well more data needs more time to be sent over the internet.  ;)
You should send as little as possible to optimize the performance / lag.
Title: Re: Difference in sending small and big packets.
Post by: Jesper Juhl on September 08, 2014, 08:54:10 pm
At the underlying layers there is a bit of overhead associated with each packet. So fewer, larger, packets utilize the available bandwidth better than more, smaller, packets.
However, for most applications that you are likely to create as a small team or just a single developer, this is rarely something you need to worry about. Focus on getting the functionality etc working. Worry about efficiency later (if it even becomes a problem at all).
Title: Re: Difference in sending small and big packets.
Post by: Veeper on September 08, 2014, 09:24:42 pm
Thanks guys  :)
Title: Re: Difference in sending small and big packets.
Post by: Nexus on September 20, 2014, 06:49:55 pm
Use neither strings nor magic numbers -- use enums.
enum struct Move { Left, Right, Up, Down };

// Overload the packet insertion and extraction operators
sf::Packet& operator<< (sf::Packet& packet, Move movement);
sf::Packet& operator>> (sf::Packet& packet, Move& movement);

// Use them
sf::Packet p;
p << Move::Left << Move::Right;

Depending on the operator implementation, a different size is used (I would recommend 8 bits). It also adds an abstraction that allows you to change the binary format without affecting the enum usage. You can also determine the underlying type directly:
enum struct Move : sf::Uint8 { ... };