Do understand that you do not have to represent only one data with a byte/whatever you are sending over the net. One byte can hold information on 8 different things if you utilize the bits for information, and not the whole byte. Saves a lot of traffic. It is also possible to use one half byte, called a nibble, to hold information, thus holding information on two things in one byte in the ranges of 0-123 each. Also never ever send meta information if this will be known on client, why sent the name of a rpg item, if that name is already known on the client? Send the id instead.
Also, when working with bytes it is good to understand bitwise operation so that you can easily get the information you need, or shift the bits to do faster calculations then when using regular arithmetic.
https://en.wikipedia.org/wiki/Bitwise_operation
https://en.wikipedia.org/wiki/Nibble
What are bytes
Bytes are data. Data is just data. Meaningless on its own.
Once you start interpreting the bytes as letters or integers or floats (fixed-point integers) or strings (collections of letters), you're dealing with information. Information is data with an associated interpretation.
It is the job of a computer program to interpret the data as information, and most likely further manipulate the information using predefined rules and presenting it to humans. In fact, computers are dumb data manipulation machines that only process data and any and all meaning associated with those data is purely in the minds of the people programming and using the machine.
So, in short, the computer never knows the bytes it receives are text or integers or approximate a Cartesian point in an imaginary universe. All of that is in the imagination of humans as the machine turns its billions of circuits on and off in response to the laws of physics.
tl;dr a program interprets bytes it receives over the network exactly the way its programmer tells it to. No more, no less.
Stephen M. Webb
Professional Free Software Developer
45 minutes ago, Bregma said:tl;dr a program interprets bytes it receives over the network exactly the way its programmer tells it to. No more, no less.
Emphasis on this, when you get down to it most API's you work with that will do things like networking are pretty much just handling sending bytes for you. At some point on the other end you have to specify what you're pulling out of the data stream. You could send two ints(4 bytes) representing an id or the damage on a weapon or something, but the other end will just get a series of 8 bytes. The API will let you pull those bytes out in any size you want(you could pull out each one, or pull out two as a short, four as an int, maybe 8.) The data itself is meaningless other than how you interpret it.
Of course to a degree API's can help you, they might let you send structs or something and more or less magically take care of the reassembling part, but when it comes down to it you're just trading bytes back and forth across the wire. This is how pointers work to a degree too, they're pointing to a particular byte at any time and you can interpret the data after that however you would like to.
In a way it's kind of the core philosophy of programming, everything is just an interpretation of data. That pretty scene on your game is just an interpretation of a bunch of numbers that were mathematically transformed to represent objects, then converted to colors for the screen to display as pixels.