Esempio n. 1
0
        /*
         * bool SettingsChanged = false;
         *
         * public void NetworkSettingsChanged()
         * {
         *  SettingsChanged = true;
         * }*/

        void DoAcceptTcpClientCallback(IAsyncResult ar)
        {
            if (!ar.IsCompleted)
            {
                return;
            }
            bool docontinue = true;

            var listener = (Socket)ar.AsyncState;

            try
            {
                var socket = listener.EndAccept(ar);

                var i2cpc = new I2CPSession(this, socket);
                Logging.LogDebug("I2CPHost: incoming connection " + i2cpc.DebugId + " from " + socket.RemoteEndPoint.ToString() + " created.");

                lock ( Sessions )
                {
                    Sessions.Add(i2cpc);
                }
            }
            catch (ObjectDisposedException)
            {
                docontinue = false;
            }
            catch (Exception ex)
            {
                Logging.Log(ex);
            }

            try
            {
                if (docontinue)
                {
                    listener.BeginAccept(new AsyncCallback(DoAcceptTcpClientCallback), listener);
                }
            }
            catch (Exception ex)
            {
                Logging.Log(ex);
            }
        }
Esempio n. 2
0
        void HandleListenerAsyncCallback(IAsyncResult ar)
        {
            if (!ar.IsCompleted)
            {
                return;
            }

            var listener  = (TcpListener)ar.AsyncState;
            var tcpclient = listener.EndAcceptTcpClient(ar);

            var i2cpc = new I2CPSession(this, tcpclient);

            Logging.LogInformation($"{this}: incoming connection ${i2cpc.DebugId} from {tcpclient.Client.RemoteEndPoint} created.");

            Sessions[(IPEndPoint)tcpclient.Client.RemoteEndPoint] = i2cpc;

            _ = i2cpc.Run();

            listener.BeginAcceptTcpClient(HandleListenerAsyncCallback, listener);
        }