internal static ITcpConnection CreateConnectingConnection(ILogger log,
                                                                  Guid connectionId, 
                                                                  IPEndPoint remoteEndPoint,
                                                                  TcpClientConnector connector,
                                                                  TimeSpan connectionTimeout,
                                                                  Action<ITcpConnection> onConnectionEstablished,
                                                                  Action<ITcpConnection, SocketError> onConnectionFailed,
                                                                  Action<ITcpConnection, SocketError> onConnectionClosed)
        {
            var connection = new TcpConnection(log, connectionId, remoteEndPoint, onConnectionClosed);
// 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;
        }
Ejemplo n.º 2
0
        public TcpTypedConnection(TcpConnection connection)
        {
            _connection = connection;
            _framer = new LengthPrefixMessageFramer();
            EffectiveEndPoint = connection.EffectiveEndPoint;

            connection.ConnectionClosed += OnConnectionClosed;

            //Setup callback for incoming messages
            _framer.RegisterMessageArrivedCallback(IncomingMessageArrived);
        }
 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;
 }
Ejemplo n.º 4
0
        public ITcpConnection ConnectTo(ILogger log,
                                        Guid connectionId,
                                        IPEndPoint remoteEndPoint,
                                        bool ssl,
                                        bool validateServer,
                                        TimeSpan timeout,
                                        Action <ITcpConnection> onConnectionEstablished         = null,
                                        Action <ITcpConnection, SocketError> onConnectionFailed = null,
                                        Action <ITcpConnection, SocketError> onConnectionClosed = null)
        {
            Ensure.NotNull(remoteEndPoint, "remoteEndPoint");
            if (ssl)
            {
                return(TcpConnectionSsl.CreateConnectingConnection(
                           log, connectionId, remoteEndPoint, validateServer,
                           this, timeout, onConnectionEstablished, onConnectionFailed, onConnectionClosed));
            }

            return(TcpConnection.CreateConnectingConnection(
                       log, connectionId, remoteEndPoint, this, timeout,
                       onConnectionEstablished, onConnectionFailed, onConnectionClosed));
        }
 internal static TcpConnection CreateAcceptedTcpConnection(IPEndPoint effectiveEndPoint, Socket socket)
 {
     var connection = new TcpConnection(effectiveEndPoint);
     connection.InitSocket(socket);
     return connection;
 }