Пример #1
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                EndPoint remoteEndPoint,
                                                                string targetHost,
                                                                bool validateServer,
                                                                TcpClientConnector connector,
                                                                TimeSpan connectionTimeout,
                                                                Action <ITcpConnection> onConnectionEstablished,
                                                                Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            // ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitClientSocket(socket, targetHost, validateServer, verbose);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
Пример #2
0
        public static ITcpConnection CreateServerFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            X509Certificate certificate,
                                                            bool verbose)
        {
            Ensure.NotNull(certificate, "certificate");
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitServerSocket(socket, certificate, verbose);
            return(connection);
        }
Пример #3
0
        public static ITcpConnection CreateClientFromSocket(Guid connectionId,
                                                            IPEndPoint remoteEndPoint,
                                                            Socket socket,
                                                            string targetHost,
                                                            bool validateServer,
                                                            bool verbose)
        {
            var connection = new TcpConnectionSsl(connectionId, remoteEndPoint, verbose);

            connection.InitClientSocket(socket, targetHost, validateServer, verbose);
            return(connection);
        }
Пример #4
0
 public ITcpConnection ConnectSslTo(Guid connectionId,
                                    IPEndPoint remoteEndPoint,
                                    TimeSpan connectionTimeout,
                                    string targetHost,
                                    bool validateServer,
                                    Action <ITcpConnection> onConnectionEstablished         = null,
                                    Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                    bool verbose = true)
 {
     Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
     Ensure.NotNullOrEmpty(targetHost, "targetHost");
     return(TcpConnectionSsl.CreateConnectingConnection(connectionId, remoteEndPoint, targetHost, validateServer,
                                                        this, connectionTimeout, onConnectionEstablished, onConnectionFailed, verbose));
 }