C#向socket通信体发送请问
·
1、 创建socket
Socket sender = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
2、建立链接
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint remoteEP = new IPEndPoint(ipAddress, 33002);
sender.Connect(remoteEP);
3、准备要发送的数据
string json = File.ReadAllText(@"E:\zx\a.txt");
byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
4、 发送数据
int bytesSent = sender123.Send(jsonBytes);
5、关闭连接
sender.Shutdown(SocketShutdown.Both);
sender.Close();
更多推荐

所有评论(0)