Пример #1
0
        //和客户端对话
        private void dealClient()
        {
            Socket     connection = this.connection;
            IPEndPoint iprm       = (IPEndPoint)connection.RemoteEndPoint;

            this.Dispatcher.Invoke(new Action(() => { TB_log.AppendText("准备接受消息!\n"); }));
            Thread receiveThread = new Thread(ReceiveMessage);

            receiveThread.Start(connection);
        }
Пример #2
0
        //public string get_remote_ip()
        //{
        //    connection = listener.AcceptSocket();
        //    //在新线程中启动新的socket连接,每个socket等待,并保持连接
        //    IPEndPoint iprm = (IPEndPoint)connection.RemoteEndPoint;
        //    return iprm.Address.ToString();
        //}

        //侦听客户连接请求
        public void runTGS()
        {
            while (true)
            {
                this.Dispatcher.Invoke(new Action(() => { TB_log.AppendText("正在监听..."); }));
                connection = listener.AcceptSocket();
                //在新线程中启动新的socket连接,每个socket等待,并保持连接
                IPEndPoint iprm = (IPEndPoint)connection.RemoteEndPoint;
                this.Dispatcher.Invoke(new Action(() => { TB_log.AppendText(DateTime.Now.ToString() + "远程主机:" + iprm.Address.ToString() + ":" + iprm.Port.ToString() + "连接上本机\r\n"); }));
                Thread thread   = new Thread(new ThreadStart(dealClient));
                Thread myThread = new Thread(dealClient);
                thread.Start();
            }
        }