Beispiel #1
0
        void AcceptTcpClient(IAsyncResult iar)
        {
            var tcs = (TcpListener)iar.AsyncState;

            TcpClient tc = null;

            try
            {
                tc = tcs.EndAcceptTcpClient(iar);
            }
            catch (Exception ex)
            {
                if (_serverComms.IsVerboseOn())
                {
                    _serverComms.LogError($"Initial SOCKS Read failed for endpoint {tcs.LocalEndpoint.ToString()} {ex.Message}".Trim());
                }
                return;
            }
            Task.Factory.StartNew(() =>
            {
                try
                {
                    if (ServerComms.IsVerboseOn())
                    {
                        ServerComms.LogMessage($"Message arrived {tcs.LocalEndpoint.ToString()} from {tc.Client.RemoteEndPoint.ToString()}".Trim());
                    }
                    (new SocksProxy()
                    {
                        TOTALSOCKETTIMEOUT = SocketTimeout
                    }).ProcessRequest(tc, WaitOnConnect);
                }
                catch (Exception ex)
                {
                    ServerComms.LogError($"Error occured on EndPoint {tcs.LocalEndpoint.ToString()} shutting down cause of {ex.Message}".Trim());
                    if (tc.Connected)
                    {
                        tc.Close();
                    }
                    return;
                }
            });

            tcs.BeginAcceptTcpClient(AcceptTcpClient, tcs);
        }