gothboiclique Posted March 31, 2021 Posted March 31, 2021 Hi again. Messing around with the built in networking (ENet), I wrote a C# app for testing with an ENet Library wrapper. I'm able to connect and send messages but I'm not quite sure how to parse a bank stream on my server's end. Any ideas from C#? For example if I send a string "this is a test" using Client:Send in Leadwerks, my server will see "? This is a test" the question mark being a wrongly parsed symbol which I assume is the message ID from Leadwerks. var dataString = Encoding.ASCII.GetString(Event.Packet.Data); Quote
Josh Posted March 31, 2021 Posted March 31, 2021 Off the top of my head, I believe the first four bytes are an integer indicating the message id. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
gothboiclique Posted March 31, 2021 Author Posted March 31, 2021 How about like floats and ints? If I use a bankstream to write a float and integer is there a certain length I can except so I can parse it? Quote
gothboiclique Posted March 31, 2021 Author Posted March 31, 2021 By the way, your suggestion was correct, I was able to take the first 4 bytes and convert them to the message ID. I will still need a way to handle the other types afterwards though like WriteFloat and WriteInt. Quote
gothboiclique Posted March 31, 2021 Author Posted March 31, 2021 int i = 0; byte[] bytes = new byte[4]; foreach (var element in Event.Packet.Data) { if (i < 4) { bytes[i] = element; } i++; } int eventId = BitConverter.ToInt32(bytes, 0); Really quick example that I'm going to turn into a BankStream class for C# but I'm able to get the Event ID and next int. Floats seem to use a different size and for strings, I'm not sure what the separation you use is. Quote
Solution Josh Posted April 1, 2021 Solution Posted April 1, 2021 Floats and integers are 4 bytes. Strings are null-terminated. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
gothboiclique Posted April 1, 2021 Author Posted April 1, 2021 Any idea on why my floats aren't reading correctly? Writing float 1 for example produces: 1.1754944E-38 Writing float 9 produces: 1.469368E-39 Here's my code: float f1 = BitConverter.ToSingle(bytes2, 0); Seems like the bytes are in a different order possibly? Quote
gothboiclique Posted April 1, 2021 Author Posted April 1, 2021 Alright, so the float bytes are reversed, I'm not sure what the technical explanation is but I am sure there is one. Floats are working properly now. Quote
Josh Posted April 1, 2021 Posted April 1, 2021 It seems surprising that C# would use a different encoding than C++. Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.