【发布时间】:2014-07-17 08:24:27
【问题描述】:
我最近接管了一项旧服务,并且正在将其转换为 PHP,但是我已经被 C# 更复杂的功能所困扰。
据我所知,请求消息长度需要打包,然后在发送到服务之前与实际消息连接。
string strReceiveBuffer;
string msg1 = string.Empty;
msg1 = msg1 + txtRqst.Text;
Int64 intMessageLength = msg1.Length;
byte byt1; byte byt2;
//The below should work assuming a 16 bit register.
byt1 = Convert.ToByte(decimal.Truncate(intMessageLength/ 256));
byt2 = Convert.ToByte(decimal.Remainder(intMessageLength, 256));
string strLength = string.Empty;
strLength = strLength
+ Microsoft.VisualBasic.Strings.Chr(byt1).ToString()
+ Microsoft.VisualBasic.Strings.Chr(byt2).ToString();
//Only encode the length using BigEndianCode, the message content is encoded using UTF8
byte[] byteData = Encoding.BigEndianUnicode.GetBytes(strLength)
.Concat(Encoding.UTF8.GetBytes(msg1)).ToArray();
在我把头发扯掉之前,有人能帮忙处理上面的代码吗?
【问题讨论】: