实现功能:
通过tcp发送信息到某led控制卡
信息从webservice获取//从webservice获取信息
string currentMsg = udpWeb.GetNewMsg(ledModel.LedType);
....
..
//部分代码省略
SendInfo(currentMsg);
//sendinfo方法
private void SendInfo(string msg)
{
msg = msg.Replace("\r\n", " ");
msg = msg.Replace("\t", " ");
//控制卡地址
IPEndPoint ipInfo = new IPEndPoint(IPAddress.Parse(ledModel.IpAddress), ledModel.IpPort);
int iwCount;//分条发送数量
Size ledSize = new Size(ledModel.Width, ledModel.Height);
byte[] bytSend = BaseHelper.ContentOfMsg(msg, ledSize, out iwCount);//发送的文字内容
//报文标题
byte[] bytTitle = BaseHelper.SendTitle(ledSize, iwCount);
byte[] bytEnd = BaseHelper.ContentEnd();//发送文字内容的末尾报文
byte[] bytTotal = new byte[bytTitle.Length + bytSend.Length + bytEnd.Length];//完整的报文内容
for (int i = 0; i < bytTitle.Length; i++)
{
bytTotal[i] = bytTitle[i];
}
for (int i = 0; i < bytSend.Length; i++)
{
bytTotal[i + bytTitle.Length] = bytSend[i];
}
for (int i = 0; i < bytEnd.Length; i++)
{
bytTotal[i + bytSend.Length + bytTitle.Length] = bytEnd[i];
}
if (tcpClient != null)
{
tcpClient.Close();
}
tcpClient = new TcpClient();
tcpClient.Connect(ipInfo); /* 发送报文头信息 **/
byte[] bytSendTT = BaseHelper.SendConect(ledSize);
NetworkStream nStream = tcpClient.GetStream();
nStream.Write(bytSendTT, 0, bytSendTT.Length);
Thread.Sleep(3000);//简化发送步骤,暂停3秒后再次发送报文信息 nStream.Write(bytTotal, 0, bytTotal.Length);
nStream.Dispose();
tcpClient.Close();
}这样发送,bytTotal的内容看了下,基本是没问题的.
但是发送有问题.
因为我测试的msg是直接写了测试的,现在是调用webservice来发送的.
如果直接发送msg,或者我把调用webservice获取到的currentMsg 写入到文件里再读取发送
发送完全没问题.
通过网络调试助手抓包,字节数一致,
通过fpe抓包发现,字节内容基本一致,但两种方法分包大小不同.
fpe分包后的记录文件,在每个包头会加上0d 0a.两中msg抓包后,主要的区别就是0d 0a的位置不同.
这是怎么回事?
通过tcp发送信息到某led控制卡
信息从webservice获取//从webservice获取信息
string currentMsg = udpWeb.GetNewMsg(ledModel.LedType);
....
..
//部分代码省略
SendInfo(currentMsg);
//sendinfo方法
private void SendInfo(string msg)
{
msg = msg.Replace("\r\n", " ");
msg = msg.Replace("\t", " ");
//控制卡地址
IPEndPoint ipInfo = new IPEndPoint(IPAddress.Parse(ledModel.IpAddress), ledModel.IpPort);
int iwCount;//分条发送数量
Size ledSize = new Size(ledModel.Width, ledModel.Height);
byte[] bytSend = BaseHelper.ContentOfMsg(msg, ledSize, out iwCount);//发送的文字内容
//报文标题
byte[] bytTitle = BaseHelper.SendTitle(ledSize, iwCount);
byte[] bytEnd = BaseHelper.ContentEnd();//发送文字内容的末尾报文
byte[] bytTotal = new byte[bytTitle.Length + bytSend.Length + bytEnd.Length];//完整的报文内容
for (int i = 0; i < bytTitle.Length; i++)
{
bytTotal[i] = bytTitle[i];
}
for (int i = 0; i < bytSend.Length; i++)
{
bytTotal[i + bytTitle.Length] = bytSend[i];
}
for (int i = 0; i < bytEnd.Length; i++)
{
bytTotal[i + bytSend.Length + bytTitle.Length] = bytEnd[i];
}
if (tcpClient != null)
{
tcpClient.Close();
}
tcpClient = new TcpClient();
tcpClient.Connect(ipInfo); /* 发送报文头信息 **/
byte[] bytSendTT = BaseHelper.SendConect(ledSize);
NetworkStream nStream = tcpClient.GetStream();
nStream.Write(bytSendTT, 0, bytSendTT.Length);
Thread.Sleep(3000);//简化发送步骤,暂停3秒后再次发送报文信息 nStream.Write(bytTotal, 0, bytTotal.Length);
nStream.Dispose();
tcpClient.Close();
}这样发送,bytTotal的内容看了下,基本是没问题的.
但是发送有问题.
因为我测试的msg是直接写了测试的,现在是调用webservice来发送的.
如果直接发送msg,或者我把调用webservice获取到的currentMsg 写入到文件里再读取发送
发送完全没问题.
通过网络调试助手抓包,字节数一致,
通过fpe抓包发现,字节内容基本一致,但两种方法分包大小不同.
fpe分包后的记录文件,在每个包头会加上0d 0a.两中msg抓包后,主要的区别就是0d 0a的位置不同.
这是怎么回事?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货