private void AcceptIncoming() { while (WantExit == false) { try { if (TcpListenerObject.Pending()) { TcpClient tc = TcpListenerObject.AcceptTcpClient(); TcpConnection vc = new TcpConnection(tc); string clientIP = ((IPEndPoint)tc.Client.RemoteEndPoint).Address.ToString(); if (connectId < 100000) Interlocked.Increment(ref connectId); else connectId = 1; vc.ID = ""+connectId; if (OnSocketError != null) vc.OnSocketError += OnSocketError; try { Monitor.Enter(ClientConnections); ClientConnections[vc.ID] = vc; //vc.ConnectId = connectId; } catch (System.Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } finally { //Monitor.Exit(ClientConnections); } } } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } Thread.Sleep(500); } }
private void ProcessVc(TcpConnection vc) { if (vc != null) { byte[] data = vc.RecvData(); if (data != null) { if (OnDataReceived != null) OnDataReceived(vc.ID, new ReceivedEventArgs(vc.ClientIP, data)); //RecvDataHandler(data, data.Length,vc.ID); //DataQueue.Enqueue(data); } } }