Beispiel #1
0
        private void AcceptTcpClientCallback(IAsyncResult asyncResult)
        {
            TcpClient tcpClient = new TcpClient();

            try
            {
                tcpClient = this.server.EndAcceptTcpClient(asyncResult);
                tcpClient.ReceiveTimeout = 4000;
                if (this.ipAddress != null)
                {
                    if (tcpClient.Client.RemoteEndPoint.ToString().Split(':')[0] != this.ipAddress)
                    {
                        tcpClient.Client.Disconnect(false);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            try
            {
                this.server.BeginAcceptTcpClient(new AsyncCallback(this.AcceptTcpClientCallback), (object)null);
                TCPHandler.Client client        = new TCPHandler.Client(tcpClient);
                NetworkStream     networkStream = client.NetworkStream;
                networkStream.ReadTimeout = 4000;
                networkStream.BeginRead(client.Buffer, 0, client.Buffer.Length, new AsyncCallback(this.ReadCallback), (object)client);
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #2
0
 private int GetAndCleanNumberOfConnectedClients(TCPHandler.Client client)
 {
     lock (this)
     {
         bool flag = false;
         foreach (TCPHandler.Client clientLastRequest in this.tcpClientLastRequestList)
         {
             if (client.Equals((object)clientLastRequest))
             {
                 flag = true;
             }
         }
         try
         {
             this.tcpClientLastRequestList.RemoveAll((Predicate <TCPHandler.Client>)(c => checked (DateTime.Now.Ticks - c.Ticks) > 40000000L));
         }
         catch (Exception ex)
         {
         }
         if (!flag)
         {
             this.tcpClientLastRequestList.Add(client);
         }
         return(this.tcpClientLastRequestList.Count);
     }
 }
Beispiel #3
0
        private void ReadCallback(IAsyncResult asyncResult)
        {
            NetworkConnectionParameter connectionParameter = new NetworkConnectionParameter();

            TCPHandler.Client asyncState = asyncResult.AsyncState as TCPHandler.Client;
            asyncState.Ticks = DateTime.Now.Ticks;
            this.NumberOfConnectedClients = this.GetAndCleanNumberOfConnectedClients(asyncState);
            // ISSUE: reference to a compiler-generated field
            if (this.numberOfClientsChanged != null)
            {
                // ISSUE: reference to a compiler-generated field
                this.numberOfClientsChanged();
            }
            if (asyncState == null)
            {
                return;
            }
            NetworkStream networkStream;
            int           count;

            try
            {
                networkStream = asyncState.NetworkStream;
                count         = networkStream.EndRead(asyncResult);
            }
            catch (Exception ex)
            {
                return;
            }
            if (count == 0)
            {
                return;
            }
            byte[] numArray = new byte[count];
            Buffer.BlockCopy((Array)asyncState.Buffer, 0, (Array)numArray, 0, count);
            connectionParameter.bytes  = numArray;
            connectionParameter.stream = networkStream;
            // ISSUE: reference to a compiler-generated field
            if (this.dataChanged != null)
            {
                // ISSUE: reference to a compiler-generated field
                this.dataChanged((object)connectionParameter);
            }
            try
            {
                networkStream.BeginRead(asyncState.Buffer, 0, asyncState.Buffer.Length, new AsyncCallback(this.ReadCallback), (object)asyncState);
            }
            catch (Exception ex)
            {
            }
        }