Esempio n. 1
0
        /// <inheritdoc cref="NtCore.AddConnectionListener"/>
        public int AddConnectionListener(ConnectionListenerCallback callback, bool immediateNotify)
        {
            Notifier notifier = m_notifier;
            int      uid      = notifier.AddConnectionListener(callback);

            notifier.Start();
            if (immediateNotify)
            {
                m_dispatcher.NotifyConnections(callback);
            }
            return(uid);
        }
Esempio n. 2
0
        public void ClientTestConnectionListener()
        {
            Console.WriteLine("ClientConnectionListener");
            m_clientDispatcher.StartClient();
            m_clientDispatcher.SetServer("localhost", 9999);

            Thread.Sleep(500);
            Notifier notifier = m_clientNotifier;

            int            retUid       = 16666;
            bool           retConnected = false;
            ConnectionInfo retInfo      = default(ConnectionInfo);

            int uid = notifier.AddConnectionListener((id, connected, connInfo) =>
            {
                retUid       = id;
                retConnected = connected;
                retInfo      = connInfo;
            });

            notifier.Start();

            m_serverDispatcher.StartServer("", "", 9999);
            Thread.Sleep(2000);

            Assert.That(retUid, Is.EqualTo(1));
            Assert.That(retConnected, Is.True);
            Assert.That(retInfo.RemoteId, Is.EqualTo("TestServer"));

            m_serverDispatcher.Stop();

            Thread.Sleep(2000);

            Assert.That(retUid, Is.EqualTo(1));
            Assert.That(retConnected, Is.False);
            Assert.That(retInfo.RemoteId, Is.EqualTo("TestServer"));
        }