예제 #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 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);
        }