|
I just learned TCP communication, but the following code is always not responding. Why?
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 ();
} |
|