0

I'm using length based message framing with python twisted framework with a C# client running BeginRecieve async reads and I'm having trouble grabbing the value of the length of the message.

This is the twisted python code

self.transport.write(pack(self.structFormat, len(string)) + string)

And this is the C# code:

int bytesRead = client.EndReceive(ar);

if (bytesRead > 0) { int msg_size = BitConverter.ToInt32(state.buffer, 0);

Problem is the len(string) value is not correct when I grab it via Bitconverter on the c# side. The value should be 15 but its coming across as 251658240.

Any insight would be much appreciated.

Mat70x7
  • 112
  • 2
  • 9
  • there is no way anyone can answer this question. You need to provide more information. Why do you expect value to be 15? what's in this string you're sending? Maybe you can share your code and add more details? At the moment your question is essentialy like saying: "I have string that I expect to be but it comes across as , why is that?". How can anyone answer question like this? – Pawel Miech Jun 09 '16 at 21:13

1 Answers1

0

Sorry the question was badly asked. I did find the solution though.

int netmsg_size = BitConverter.ToInt32(state.buffer, 0);

int msg_size = IPAddress.NetworkToHostOrder(netmsg_size);

This converts the network integer back into a regular integer.

Community
  • 1
  • 1
Mat70x7
  • 112
  • 2
  • 9