Пример #1
0
 public void Dispose()
 {
     foreach (var connection in connectionList)
     {
         RemoveEventHandlerNotifications(connection);
         connection.Dispose();
     }
     connectionList.Clear();
     acceptor.AcceptNotification -= AcceptNotification;
     acceptor?.Dispose();
     reactor?.Dispose();
 }
Пример #2
0
        public void SetUp()
        {
            acceptor = new UdpAcceptor(IPAddress.Any, 8765,
                new TransportFactory<UdpHandle>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedServerTestTransport(h),
                    t => t is UdpSequencedServerTestTransport));
            connector = new UdpConnector(
                new TransportFactory<UdpClient>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedClientTestTransport(h),
                    t => t is UdpSequencedClientTestTransport));

            acceptor.NewTransportAccepted += delegate(ITransport transport, IDictionary<string, string> capabilities)
            {
                serverTransport = (UdpSequencedServerTestTransport)transport;
            };
            acceptor.Start();
            Thread acceptorThread = new Thread(delegate()
            {
                for (int i = 0; serverTransport == null && i < 100; i++)
                {
                    try
                    {
                        acceptor.Update();
                        Thread.Sleep(50);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Acceptor Thread: " + e);
                    }
                }
            });
            acceptorThread.IsBackground = true;
            acceptorThread.Name = "Acceptor Thread";
            acceptorThread.Start();
            Thread.Sleep(50);

            clientTransport = (UdpSequencedClientTestTransport)connector.Connect("127.0.0.1", "8765", new Dictionary<string, string>());
            acceptorThread.Join();
            Assert.IsNotNull(clientTransport);
            Assert.IsNotNull(serverTransport);

            acceptor.Dispose();
            connector.Dispose();
        }