Beispiel #1
0
 public void WatchConnecting()
 {
     try
     {
         listener = new TcpListener(IPAddress.Parse(Host), Port);
         listener.Start(20);
         // 开始监听客户端连接请求,Accept方法会阻断当前的线程;
         // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字;
         while (IsActive)
         {
             TcpClient             client    = listener.AcceptTcpClient();
             HttpProcessor         processor = new HttpProcessor(this, client);
             DelegateSocketMessage caller    = new DelegateSocketMessage(processor.Process);
             IAsyncResult          result    = caller.BeginInvoke(null, null);
             string message = caller.EndInvoke(result);
             UIDelegateUIMessage(message);
             //Console.Write(message);
         }
         if (listener != null)
         {
             listener.Stop();
         }
     }
     catch
     {
         if (listener != null)
         {
             IsActive = false;
             listener.Stop();
         }
     }
 }
Beispiel #2
0
 public void WatchConnecting(Object socketObject)
 {
     try
     {
         //Console.WriteLine("服务器正在监听...");
         SocketParameter socketParameter = socketObject as SocketParameter;
         while (running)
         {
             // 开始监听客户端连接请求,Accept方法会阻断当前的线程;
             // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字;
             Socket                socketClient      = _Watchsocket.Accept();
             CallServiceThread     callServiceThread = new CallServiceThread(socketClient);
             DelegateSocketMessage caller            = new DelegateSocketMessage(callServiceThread.ReceiveMessage);
             IAsyncResult          result            = caller.BeginInvoke(socketParameter, null, null);
             string                message           = caller.EndInvoke(result);
             UIDelegateUIMessage(message);
             //Console.Write(message);
         }
         if (_Watchsocket != null)
         {
             _Watchsocket.Close();
             _Watchsocket.Dispose();
         }
     }
     catch
     {
         //Console.WriteLine(e.Message);
         if (_Watchsocket != null)
         {
             _Watchsocket.Close();
             _Watchsocket.Dispose();
         }
     }
 }