コード例 #1
0
        public ClientState(IPAddress remoteAddr, Net.NetworkStream streamEnclosure)
        {
            this._RemoteAddr      = remoteAddr;
            this._StreamEnclosure = streamEnclosure;

            this._StateID = Guid.NewGuid().ToString();
        }
コード例 #2
0
        private async void EstablishConnection(IPEndPoint remoteIPEndPoint, TcpClient remoteClient)
        {
            Stream remoteStream = remoteClient.GetStream();

            if (ConfigurationManager.Current.Configuration.Service.Ssl)
            {
                remoteStream = new SslStream(remoteStream, false);

                try
                {
                    ((SslStream)remoteStream).AuthenticateAsServer(this._Certificate, false, System.Security.Authentication.SslProtocols.Tls12, true);
                }
                catch (IOException ex)
                {
                    Basics.Console.Push("Connection is rejected from", string.Format("{0} ({1})", remoteIPEndPoint, ex.Message), true);

                    remoteStream.Close();
                    remoteStream.Dispose();

                    return;
                }
                catch (System.Exception ex)
                {
                    Basics.Console.Push("Ssl Connection FAILED!", ex.ToString(), false, true);

                    remoteStream.Close();
                    remoteStream.Dispose();

                    return;
                }
            }

            // If reads create problems and put the loop to infinite. drop the connection.
            // that's why, 5 seconds timeout should be set to remoteStream
            // No need to put timeout to write operation because xeora will handle connection state
            remoteStream.ReadTimeout = READ_TIMEOUT * 1000;

            Net.NetworkStream streamEnclosure = new Net.NetworkStream(remoteStream);

            Basics.Console.Push("Connection is accepted from", string.Format("{0} ({1})", remoteIPEndPoint, ConfigurationManager.Current.Configuration.Service.Ssl ? "Secure" : "Basic"), true);

            ClientState clientState = new ClientState(remoteIPEndPoint.Address, streamEnclosure);
            await Task.Run(() => clientState.Handle());

            clientState.Dispose();

            streamEnclosure.Dispose();

            remoteClient.Close();
            remoteClient.Dispose();
        }
コード例 #3
0
        public void Process()
        {
            if (this.ProceedStream(out Stream remoteStream))
            {
                // If reads create problems and put the loop to infinite. drop the connection.
                // that's why, 5 seconds timeout should be set to remoteStream
                // No need to put timeout to write operation because xeora will handle connection state
                remoteStream.ReadTimeout = READ_TIMEOUT;

                Net.NetworkStream streamEnclosure =
                    new Net.NetworkStream(ref remoteStream);

                this.Handle(ref streamEnclosure);
            }

            remoteStream.Close();
            remoteStream.Dispose();

            this._RemoteClient.Close();
            this._RemoteClient.Dispose();

            Basics.Console.Flush();
        }
コード例 #4
0
 private void Handle(ref Net.NetworkStream remoteStream)
 {
     Basics.Console.Push("Connection is accepted from", string.Format("{0} ({1})", this._RemoteIpEndPoint, Configuration.Manager.Current.Configuration.Service.Ssl ? "Secure" : "Basic"), string.Empty, true);
     ClientState.Handle(this._RemoteIpEndPoint.Address, remoteStream);
 }