|
刚学习tcp通讯,但下面的代码老是没有响应,为什么?
TcpListener tcplistener = new TcpListener(IPAddress.Parse("127.0.0.1"),13);
tcplistener.Start();
byte[] btServerReceive = new byte[256];
string strServerReceive = string.Empty;
while (true)
{
TcpClient tcp = tcplistener.AcceptTcpClient();
NetworkStream ns = tcp.GetStream();
int intReceiveLength = ns.Read(btServerReceive, 0, btServerReceive.Length);
strServerReceive = UnicodeEncoding.Unicode.GetString(btServerReceive, 0, intReceiveLength);
txtServerResult.AppendText("ServerReceive:" + strServerReceive + " ");
ns.Write(btServerReceive, 0, btServerReceive.Length);
txtServerResult.AppendText("ServerSend:" + strServerReceive + " ");
tcp.Close();
} |
|