Beispiel #1
0
        public void BeginConnect(string address, int port, bool useSsl)
        {
            if (_session != null)
            {
                _session.Close();
                _session   = null;
                _sslStream = null;
                _socket    = null;
            }

            _secureConnect  = useSsl;
            _socket         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.NoDelay = NoDelay;
            _socket.BeginConnect(address, port, ProcessConnect, this);
        }
Beispiel #2
0
        private void OnClientAutenticated(IAsyncResult ar)
        {
            var        sslConnection = (SslConnection)ar.AsyncState;
            TcpSession session       = null;

            try {
                sslConnection.SslStream.EndAuthenticateAsServer(ar);
                session = new TcpSession(sslConnection.Socket, sslConnection.SslStream);

                try {
                    if (OnClientConnected != null)
                    {
                        OnClientConnected(session);
                    }
                } catch (Exception) {
                    // ignored
                }

                session.Start();
            } catch (Exception e) {
                try {
                    if (OnError != null)
                    {
                        OnError(e);
                    }
                } catch (Exception) {
                    // ignored
                }

                if (session != null)
                {
                    session.Close();
                }
                else
                {
                    sslConnection.SslStream.Close();
                    sslConnection.Socket.Close();
                }
            }
        }