Exemplo n.º 1
0
        public static ITcpConnection CreateConnectingTcpConnection(Guid connectionId,
                                                                   IPEndPoint localEndPoint,
                                                                   IPEndPoint remoteEndPoint,
                                                                   TcpClientConnector connector,
                                                                   Action <ITcpConnection> onConnectionEstablished,
                                                                   Action <ITcpConnection, SocketError> onConnectionFailed)
        {
            var connection = new TcpConnection(connectionId, remoteEndPoint);

            connector.InitConnect(localEndPoint, remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection);
            return(connection);
        }
Exemplo n.º 2
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);

            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            }, connection, connectionTimeout);
            return(connection);
        }
Exemplo n.º 3
0
 public SocketClient()
 {
     var remoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DEFAULT_PORT);
     var connector = new TcpClientConnector();
     _connection = connector.ConnectTo(_connectionId, remoteEndPoint, ConnectionTimeout, OnConnectionEstablished, OnConnectionFailed);
     _connection.ConnectionClosed += OnConnectionClosed;
     _connection.ReceiveAsync(OnRawDataReceived);
 }
Exemplo n.º 4
0
 public static ITcpConnection CreateConnectingTcpConnection(Guid connectionId,
                                                            IPEndPoint localEndPoint,
                                                            IPEndPoint remoteEndPoint,
                                                            TcpClientConnector connector,
                                                            Action<ITcpConnection> onConnectionEstablished,
                                                            Action<ITcpConnection, SocketError> onConnectionFailed)
 {
     var connection = new TcpConnection(connectionId, remoteEndPoint);
     connector.InitConnect(localEndPoint, remoteEndPoint,
                           (_, socket) =>
                           {
                               connection.InitSocket(socket);
                               if (onConnectionEstablished != null)
                                   onConnectionEstablished(connection);
                           },
                           (_, socketError) =>
                           {
                               if (onConnectionFailed != null)
                                   onConnectionFailed(connection, socketError);
                           }, connection);
     return connection;
 }
Exemplo n.º 5
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;
 }