Пример #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;
        }
Пример #2
0
        public void Open()
        {
            if (IsOpened)
            {
                return;
            }

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

            int port = portNumber;

            if (listenPortNumber != 0)
            {
                port = listenPortNumber;
            }

            udpTerminal             = new UDPTerminal(port, bufferSize);
            udpTerminal.SyncContext = syncContext;
            udpTerminal.OnReceive  += OnUnreliableReceived;

            udpTerminal.ReceiveStart();

            IsOpened = true;
        }
Пример #3
0
 public void BeaconStop()
 {
     if (beaconTimer != null)
     {
         beaconTimer.Stop();
         beaconTimer = null;
         udpBeaconSender.Close();
         udpBeaconSender = null;
     }
 }
Пример #4
0
 public void BeaconStart()
 {
     if (udpBeaconSender == null)
     {
         udpBeaconSender             = new UDPTerminal(UDPTerminal.DefaultBufferSize);
         udpBeaconSender.SyncContext = syncContext;
         beaconTimer          = new System.Timers.Timer(BeaconIntervalMs);
         beaconTimer.Elapsed += OnBeaconTimer;
         beaconTimer.Start();
     }
 }
Пример #5
0
        public void Close()
        {
            if (!IsOpened)
            {
                return;
            }

            if (udpTerminal != null)
            {
                udpTerminal.Close();
                udpTerminal = null;
            }

            IsOpened = false;
        }
Пример #6
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();
        }
Пример #7
0
        public void Close()
        {
            if (!IsOpened)
            {
                return;
            }

            healthTimer.Stop();

            AcceptBeacon = false;

            Disconnect();

            udpTerminal.Close();

            tcpConnector = null;
            udpTerminal  = null;

            IsOpened = false;
        }
Пример #8
0
        public void Open()
        {
            if (IsOpened)
            {
                return;
            }

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

            int port = PortNumber;

            if (listenPortNumber != 0)
            {
                port = listenPortNumber;
            }
            udpTerminal             = new UDPTerminal(port, bufferSize);
            udpTerminal.SyncContext = syncContext;
            udpTerminal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            udpTerminal.OnReceive += OnUnreliableReceived;

            tcpConnector                        = new TCPConnector(portNumber);
            tcpConnector.SyncContext            = syncContext;
            tcpConnector.ConnectionBufferSize   = bufferSize;
            tcpConnector.ConnectTimeOutMilliSec = connectTimeOutMilliSec;
            tcpConnector.OnConnected           += OnConnectedInternal;

            IsOpened = true;

            healthTimer.Start();

            UdpCheck();
        }