public static ITcpConnection CreateConnectingTcpConnection(Guid connectionId, 
                                                                   IPEndPoint remoteEndPoint, 
                                                                   TcpClientConnector connector, 
                                                                   TimeSpan connectionTimeout,
                                                                   Action<ITcpConnection> onConnectionEstablished, 
                                                                   Action<ITcpConnection, SocketError> onConnectionFailed,
                                                                   bool verbose)
        {
            var connection = new TcpConnectionLockless(connectionId, remoteEndPoint, verbose);
// ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
                                  {
                                      if (connection.InitSocket(socket))
                                      {
                                          if (onConnectionEstablished != null)
                                              onConnectionEstablished(connection);
                                          connection.StartReceive();
                                          connection.TrySend();
                                      }
                                  },
                                  (_, socketError) =>
                                  {
                                      if (onConnectionFailed != null)
                                          onConnectionFailed(connection, socketError);
                                  }, connection, connectionTimeout);
// ReSharper restore ImplicitlyCapturedClosure
            return connection;
        }
示例#2
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                IPEndPoint remoteEndPoint,
                                                                bool validateServer,
                                                                X509CertificateCollection clientCertificates,
                                                                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);
            },
                                  (_, socket) => {
                connection.InitSslStream(remoteEndPoint.Address.ToString(), validateServer, clientCertificates, verbose);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) => {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
示例#3
0
        public static ITcpConnection CreateConnectingTcpConnection(Guid connectionId,
                                                                   IPEndPoint remoteEndPoint,
                                                                   TcpClientConnector connector,
                                                                   TimeSpan connectionTimeout,
                                                                   Action <ITcpConnection> onConnectionEstablished,
                                                                   Action <ITcpConnection, SocketError> onConnectionFailed,
                                                                   bool verbose)
        {
            var connection = new TcpConnection(connectionId, remoteEndPoint, verbose);

// ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
// ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
示例#4
0
        public static ITcpConnection CreateConnectingConnection(Guid connectionId,
                                                                string targetHost,
                                                                IPEndPoint remoteEndPoint,
                                                                Func <X509Certificate, X509Chain, SslPolicyErrors, ValueTuple <bool, string> > serverCertValidator,
                                                                Func <X509CertificateCollection> clientCertificatesSelector,
                                                                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);
            },
                                  (_, socket) => {
                connection.InitSslStream(targetHost, serverCertValidator, clientCertificatesSelector, verbose);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) => {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            // ReSharper restore ImplicitlyCapturedClosure
            return(connection);
        }
示例#5
0
 public static ITcpConnection CreateConnectingConnection(Guid connectionId, 
                                                         IPEndPoint 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;
 }
示例#6
0
        internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint,
                                                                    TcpClientConnector connector,
                                                                    Action <TcpConnection> onConnectionEstablished,
                                                                    Action <TcpConnection, SocketError> onConnectionFailed)
        {
            var connection = new TcpConnection(remoteEndPoint);

            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
                connection.TrySend();
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            });
            return(connection);
        }
 internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint, 
                                                             TcpClientConnector connector, 
                                                             Action<TcpConnection> onConnectionEstablished, 
                                                             Action<TcpConnection, SocketError> onConnectionFailed)
 {
     var connection = new TcpConnection(remoteEndPoint);
     connector.InitConnect(remoteEndPoint,
                           (_, socket) =>
                           {
                               connection.InitSocket(socket);
                               if (onConnectionEstablished != null)
                                   onConnectionEstablished(connection);
                               connection.TrySend();
                           },
                           (_, socketError) =>
                           {
                               if (onConnectionFailed != null)
                                   onConnectionFailed(connection, socketError);
                           });
     return connection;
 }
示例#8
0
        public static ITcpConnection CreateConnectingTcpConnection(Guid connectionId, 
                                                                   IPEndPoint remoteEndPoint, 
                                                                   TcpClientConnector connector, 
                                                                   Action<ITcpConnection> onConnectionEstablished, 
                                                                   Action<ITcpConnection, SocketError> onConnectionFailed,
                                                                   bool verbose)
        {
            var connection = new TcpConnection(connectionId, remoteEndPoint, verbose);
// ReSharper disable ImplicitlyCapturedClosure
            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
                                  {
                                      connection.InitSocket(socket);
                                      if (onConnectionEstablished != null)
                                          onConnectionEstablished(connection);
                                  },
                                  (_, socketError) =>
                                  {
                                      if (onConnectionFailed != null)
                                          onConnectionFailed(connection, socketError);
                                  });
// ReSharper restore ImplicitlyCapturedClosure
            return connection;
        }