把监听放到监听按钮内
============================
接收端:
监听函数:
public TcpListener listener;//定义一个监听
private void Listen()
{
   socket = listener.AcceptSocket();
  while(true)
  {
    string strTxt = string.Empty;
    strTxt = CommunicationBase.ReadTextFromSocket(socket lbReceiveMessage.Items.Add( strTxt);
  }
}
监听按钮:
private void btnIntercept_Click(object sender, System.EventArgs e)
{
  listener = new TcpListener(Int32.Parse(txtClientPort.Text)); //<-
  listener.Start();                                            //<-
  Thread th = new Thread(new ThreadStart(Listen));
  th.Start();
}

解决方案 »

  1.   

    老弟,几天不见。钻到这了^_^
    你的程序逻辑有问题:
    你的btnSend_Click()事件,每点击一下,都是建立一个新的对象,就是说从头建立连接等网络操作,
    而 你的侦听函数,是先socket = listener.AcceptSocket(); //接受刮起的连接请求,当客户端来了一个请求时,此举响应,以后进入while(),当客户端二度连接请求时,没有了接受操作,呵呵
    所以把监听函数改成:
    private void Listen()
    {
      TcpListener listener = new TcpListener(Int32.Parse(txtClientPort.Text));
      listener.Start();//<<<<---
      
      while(true)
      {
        socket = listener.AcceptSocket();//<<<<---
        string strTxt = string.Empty;
        strTxt = CommunicationBase.ReadTextFromSocket(socket);//该方法是从socket中读取文本
        lbReceiveMessage.Items.Add( strTxt);
      }
    }
    即可!
    或者在客户端保持一个“全局”的socket连接,设个按钮“连接服务器”,以后一直用这个socket!
    understand???^_^