Example #1
0
        //侦听客户连接请求
        public void runAs()
        {
            while (true)
            {
                this.Dispatcher.Invoke(new Action(() => { T1.AppendText("Waiting for Connection\r\n"); }));
                connection = listener.AcceptSocket();
                //在新线程中启动新的socket连接,每个socket等待,并保持连接

                IPEndPoint iprm = (IPEndPoint)connection.RemoteEndPoint;
                this.Dispatcher.Invoke(new Action(() => { T1.AppendText("远程主机:" + iprm.Address.ToString() + ":" + iprm.Port.ToString() + "连接上本机" + DateTime.Now.ToString() + "\n"); }));
                Thread thread   = new Thread(new ThreadStart(dealClient));
                Thread myThread = new Thread(dealClient);
                thread.Start();
            }
        }