I'm making a game in C# that uses sockets to transfer data between players including three floats for the position and one for rotation. Currently I'm doing this with strings encoded to binary and I know that this is very inefficient and could cause issues at 32 updates per second with 5 players on a server especially due to having to convert from float to string and back and splitting strings. I think serialisation could be good due to (I assume) its space efficiency and speed. I'm still unsure about a few things though:
- Is it more space efficient?
- Is it faster to serialise than convert to a string?
- How would I separate objects? (I used "<EOF>" to know where each update ended with strings)
- Is serialisation a good idea?
- Are there any other recommended alternatives
CodePudding user response:
I won't be using the binary serializer because as outlined here it is a massive security vulnerability
CodePudding user response:
It's a big topic. You can use a well known serialisation library , communications framework or build your own. Have a look at Message pack, Protocol buffers gRPC and so on for libraries and frameworks. If you want to build it all yourself I'd recommend using fixed frames. Have a look at Stephen Cleary's blog entry about Message Framing as well as the new IO Pipelines too especially if you want to build a terminator separated protocol yourself.