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

Author Topic: Difference in sending small and big packets.  (Read 3407 times)

0 Members and 2 Guests are viewing this topic.

Veeper

  • Newbie
  • *
  • Posts: 9
    • View Profile
Difference in sending small and big packets.
« 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

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Difference in sending small and big packets.
« Reply #1 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.
Failing to succeed does not mean failing to progress!

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Difference in sending small and big packets.
« Reply #2 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).

Veeper

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Difference in sending small and big packets.
« Reply #3 on: September 08, 2014, 09:24:42 pm »
Thanks guys  :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Difference in sending small and big packets.
« Reply #4 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 { ... };
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything