在C中通过TCP IP发送号码#
我想通过TCP IP发送一个整数。我将数据保存在在C中通过TCP IP发送号码#,tcp,ip,Tcp,Ip,我想通过TCP IP发送一个整数。我将数据保存在Send_data中,作为整数的数字 我无法将其更改为字符串或char[]以发送它。当我运行此代码时,我只在客户机中收到一个空格 这是我的代码: NetworkStream clientStream = MyClient.GetStream(); ASCIIEncoding encoder = new ASCIIEncoding(); byte[] buffer = BitConverter.GetBytes(Send_data[0]); clie
Send_data
中,作为整数
的数字
我无法将其更改为字符串
或char[]
以发送它。当我运行此代码时,我只在客户机中收到一个空格
这是我的代码:
NetworkStream clientStream = MyClient.GetStream();
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] buffer = BitConverter.GetBytes(Send_data[0]);
clientStream.Write(buffer, 0, buffer.Length);
clientStream.Flush();
tcp客户端声明和连接:
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("IP_address"), port);
TcpClient client = new TcpClient();
client.Connect(endPoint);
网络流声明:
NetworkStream networkStream = client.GetStream();
用于序列化的二进制格式化程序
BinaryFormatter formatter = new BinaryFormatter();
//int goes here
formatter.Serialize(networkStream , Send_data);
发送数据[0]
中的值是多少?