Comments (3)
"sometimes 11" is very odd and shouldn't be happening unless you haven't read out all your "real" data
Given my silly typo in my other issue I think this was also just user error, I went through and checked all my current messages and when they arrive they never have more than 7 bits of padding. My bad again 🙏
from riptide.
It's not so much "intended" as it is expected. Bytes are the smallest unit of data that you can send over the network, so if a message consists of 60 bits (7.5 bytes) it will be sent as 8 bytes, with the last 4 bits being empty "filler" data. The receiving end will see that it received 8 bytes and set the writeBit
(which is used to calculate UnreadBits
) to 8 bytes * 8 bits per byte = 64 bits, even though the last 4 bits technically shouldn't be interpreted as data.
To prevent this from happening, senders would have to write the total number of usable bits into the message itself (near the beginning) so the receiver can read it and know exactly where the data ends. I figured this extra overhead wasn't worth it, especially since it's easy to implement yourself if you really want/need it. Additionally, you probably shouldn't be relying on there being a specific number of bits left over for any logic decisions, as a malicious client could send more or less bits (or manipulate/lie about the length value) and thereby cause problems.
The number of "extra" UnreadBits
that remain after you read out all your data depends on how many bits it takes to round up to the nearest byte, meaning that you should never be seeing more than 7 "extra" bits on the receiving end. The fact that you say it's "sometimes 11" is very odd and shouldn't be happening unless you haven't read out all your "real" data...
In the example you gave, UnreadBits
should always be returning 4. If it's changing/fluctuating then that's also concerning.
from riptide.
Thank you! Lack of knowledge from me, I just assumed network data was sent as bits, now the padding makes sense. And I was not using it for any game logic, it was just something I noticed when I added some sanity-checks around the code, one of them checking that all data was read. I'll just change the check to account for this padding. Cheers!
from riptide.
Related Issues (20)
- Handling player servers inside Master Server HOT 2
- Feature Request | Restriction to bytes length send separately to server and client HOT 5
- Bug | Eating bytes if is count more than 32767 (Message only contains 7170 unread bytes, which is not enough to retrieve 72706 bytes! Returned array will contain default elements) HOT 2
- dose it work on sanctioned countrys HOT 1
- The second client to connect is disconnected because a reliable message can't be delivered
- Serialisation Bug HOT 1
- Client _._._._:_ stopped responding while the connection was fully established! HOT 4
- Suggestion for AddBytes method HOT 1
- Show message id when reliable message fails to ack in PendingMessage.TrySend HOT 1
- [Question] Example usage of Notify send mode? HOT 7
- [Bug] Some values not being read properly HOT 2
- Simulating network conditions (latency/ping, packet loss, etc.) HOT 2
- Reliability of reliable messages HOT 2
- Change Id method HOT 2
- Better packet model handling HOT 1
- Seperate server and client library HOT 1
- PlayerLeft event Hook in NetworkManager not working HOT 1
- MessageExtensionUnity.cs missing in Repo HOT 1
- Switch to nanosockets to minimize allocations HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from riptide.