Ejemplo n.º 1
0
 public ConnectionComponent(NetworkAddress networkAddress, string connectionManagerIpAddress,
                            int connectionManagerListeningPort, ConnectionManagerType connectionManagerType)
 {
     _ipAddress = IPAddress.Parse(connectionManagerIpAddress);
     _connectionManagerListeningPort = connectionManagerListeningPort;
     _connectionManagerType          = connectionManagerType;
     _handshakeMessage      = new ConnectionRequestMessage(networkAddress, PortRandomizer.RandomFreePort());
     _connectionManagerType = connectionManagerType;
 }
        private void ConnectToNode(ConnectionRequestMessage connectionRequestMessage)
        {
            var nodeTcpClient = new TcpClient();

            var port = connectionRequestMessage.SocketPort;
            var clientNetworkAddress = connectionRequestMessage.NetworkAddress;

            try {
                EstablishConnection(nodeTcpClient, port, clientNetworkAddress);
                OnUpdateState($"[ACCEPTED] {clientNetworkAddress}");
                Listen(nodeTcpClient, clientNetworkAddress).Start();
            }
            catch (SocketException e) {
                DeleteConnection(clientNetworkAddress);
                OnUpdateState($"[FAILED] {clientNetworkAddress}");
                OnUpdateState(e.Message);
            }
        }