|
楼主发表于:2009-01-10 00:44:09
private const int portNum = 13; private void Form1_Load(object sender, EventArgs e) { bool done = false; IPAddress local = IPAddress.Parse("127.0.0.1"); TcpListener listener = new TcpListener(local,portNum); listener.Start(); while (!done) { textBox1.Text += "waiting for connection..."; TcpClient client = listener.AcceptTcpClient();//在这一行就不动了。界面显示不了。也不抛出异常 textBox1.Text += "Connection accepted\r\n"; NetworkStream ns= client.GetStream(); byte[] byteTime = Encoding.ASCII.GetBytes(DateTime.Now.ToString()); try { ns.Write(byteTime, 0, byteTime.Length); ns.Close(); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } listener.Stop(); } |
|
|
|