Book Image

SFML Blueprints

Book Image

SFML Blueprints

Overview of this book

Table of Contents (15 chapters)
SFML Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a communication protocol


It's now time for us to create our own custom protocol. We will use an SFML class sf::Packet to transport our data, but we have to define their shapes. Let's first focus on the sf::Packet class and then on the shapes.

Using the sf::Packet class

The sf::Packet class is like a buffer that contains our data. It comes with already-made functions that allow us to serialize primitive types. I don't know if you are familiar with the internal memory storage of computers, but keep in mind that the arrangement is not the same everywhere. This is called endianness. You can see it like reading from the right or from the left. When you send data over the network, you don't know the endianness of the destination. Because of this, the convention is to send data as a big-endian arrangement over the network. I suggest you to take a look at the Wikipedia page (https://en.wikipedia.org/wiki/Endianness) for more details.

Thanks to SFML, there are some pre-existing functions that...