Python Twisted frameowrk transport.write到c#套接字BeginReceive读取长度的消息框架值

时间:2016-06-09 06:19:22

标签: c# python sockets twisted beginreceive

我正在使用基于长度的消息框架与python扭曲框架和运行BeginRecieve异步读取的C#客户端,我无法抓取消息长度的值。

这是扭曲的python代码

  

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

这是C#代码:

  

int bytesRead = client.EndReceive(ar);

     

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

当我通过c#端的Bitconverter获取它时,问题是len(字符串)值不正确。 该值应为15,但其值为251658240。

非常感谢任何见解。

1 个答案:

答案 0 :(得分:0)

对不起,问题很严重。我确实找到了解决方案。

  

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

     

int msg_size = IPAddress.NetworkToHostOrder(netmsg_size);

这会将网络整数转换回常规整数。

相关问题