Beispiel #1
0
        public void Close()
        {
            if (!IsOpened)
            {
                return;
            }

            healthTimer.Stop();
            removeNodeCheckTimer.Stop();

            var nMap = new Dictionary <IPEndPoint, ComNode>(nodeTcpMap);

            foreach (var node in nMap)
            {
                ((ComSnowballNode)node.Value).Connection.Disconnect();
            }

            tcpListener.Stop();
            udpTerminal.Close();

            tcpListener = null;
            udpTerminal = null;

            IsOpened = false;
        }
Beispiel #2
0
        public void Close()
        {
            if (!IsOpened)
            {
                return;
            }

            beaconTimer.Stop();

            var nMap = new Dictionary <string, ComNode>(nodeMap);

            foreach (var node in nMap)
            {
                ((ComTCPNode)node.Value).Connection.Disconnect();
            }

            tcpListener.Stop();
            udpReceiver.Close();

            beaconTimer = null;

            tcpListener = null;
            udpReceiver = null;
            udpSender   = null;

            IsOpened = false;
        }
Beispiel #3
0
        public void Open()
        {
            if (IsOpened)
            {
                return;
            }

            if (Global.UseSyncContextPost && Global.SyncContext == null)
            {
                Global.SyncContext = SynchronizationContext.Current;
            }

            udpSender   = new UDPSender(sendPortNumber, bufferSize);
            udpReceiver = new UDPReceiver(listenPortNumber, bufferSize);

            tcpListener = new TCPListener(listenPortNumber);
            tcpListener.ConnectionBufferSize = bufferSize;
            tcpListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            tcpListener.OnConnected += OnConnectedInternal;

            beaconTimer = new System.Timers.Timer(BeaconIntervalMs);

            udpReceiver.OnReceive += OnUDPReceived;

            beaconTimer.Elapsed += OnBeaconTimer;

            tcpListener.Start();
            udpReceiver.Start();

            IsOpened = true;

            HealthCheck();
        }
Beispiel #4
0
        public void Open()
        {
            if (IsOpened)
            {
                return;
            }

            if (userSyncContext)
            {
                syncContext = SynchronizationContext.Current;
                if (syncContext == null)
                {
                    syncContext = new SnowballSynchronizationContext(10);
                    SynchronizationContext.SetSynchronizationContext(syncContext);
                }
            }

            RSAParameters publicKey;
            RSAParameters privateKey;

            RsaKeyGenerate(out publicKey, out privateKey);
            RsaPublicKey  = publicKey;
            RsaPrivateKey = privateKey;

            rsaDecrypter = new RsaDecrypter(RsaPrivateKey);

            udpTerminal             = new UDPTerminal(portNumber, bufferSize);
            udpTerminal.SyncContext = syncContext;
            udpTerminal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

            tcpListener                      = new TCPListener(portNumber);
            tcpListener.SyncContext          = syncContext;
            tcpListener.ConnectionBufferSize = bufferSize;
            tcpListener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            tcpListener.OnConnected += OnConnectedInternal;

            udpTerminal.OnReceive += OnUnreliableReceived;

            tcpListener.Start();

            udpTerminal.ReceiveStart();

            IsOpened = true;

            healthTimer.Start();
            removeNodeCheckTimer.Start();
        }