Пример #1
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();
        }
Пример #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.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();
        }