|
发表于 2020-3-23 23:00:01
|
显示全部楼层
TcpListener MyTcpListener = new TcpListener(9999);
MyTcpListener.Start();
TcpClient MyTcpClient = MyTcpListener.AcceptTcpClient();
NetworkStream MyStream = MyTcpClient.GetStream();
byte[] MyBytes = new byte[1024];
int MyBytesRead = MyStream.Read(MyBytes, 0, MyBytes.Length);
string MyMessage = System.Text.Encoding.Default.GetString(MyBytes, 0, MyBytesRead);
string cmd = MyMessage;
//this.richTextBox1.Text += cmd.Substring(4, 11);
cmd = "HELLO WORLD!";
byte[] byteTime = Encoding.ASCII.GetBytes(cmd);
MyStream.Write(byteTime, 0, byteTime.Length);
//MyStream.Flush();
MyStream.Close();
MyTcpClient.Close();
Console.Read(); |
|