我在 c# 中的应用程序想要与第 3 方 Tcp 服务器联合发送数据并接收回响应消息...命令的语法有 UShort、ULONG、BYTE 类型数据,我的应用程序需要发送的示例命令是
USHORT 0xFFFF
USHORT 0x00D0
BYTE 0xDD
然后在应用程序中我发送数据为
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("XX.XX.XX.XX",portnumber);
Networkstream ns=tcpClient.GetStream();
StreamWriter sw=new StreamWriter(ns);
sw.Write(0xFFFF);
sw.Write(0x00DD);
sw.Write(0x00);
//或向他们发送字节
sw.Write(0xFF);
sw.Write(0xFF);
sw.Write(0x00);
sw.Write(0xD0);
sw.Write(0x00);
sw.Write(0x00);
我通过服务器读取传入的消息
while (true)
{
byte[] buff=new byte[tcpClient.ReceiveBufferSize];
ns.Read(buff, 0, tcpClient.ReceiveBufferSize);
string dv= BitConverter.ToString(buff));
}
//returned data looks like FF-A2-00-23-00-02-00-00-00-00-00-00-D9-2E-20-2E-00-A0-04-00-AE-08
//yes i know this byte syntaxes but returning data is not that i look response for command that i sent..
但返回值不是我要寻找的我的代码向服务器发送数据有什么问题吗?欢迎任何关于阅读写入数据的建议......