Beispiel #1
0
        public void TestUdpAutoDetermination()
        {
            UdpAcceptor acc = new UdpAcceptor(IPAddress.Loopback, 9999);
            Thread acceptorThread = null;
            try
            {
                acc.Start();
                acceptorThread = new Thread(delegate()
                {
                    while(acc.Active)
                    {
                        try
                        {
                            acc.Update();
                            Thread.Sleep(50);
                        }
                        catch (Exception e)
                        {
                            if (!(e is ThreadAbortException))
                            {
                                Console.WriteLine("Acceptor Thread: " + e);
                            }
                        }
                    }
                });
                acceptorThread.IsBackground = true;
                acceptorThread.Name = "Acceptor Thread";
                acceptorThread.Start();
                Thread.Sleep(50);

                UdpConnector conn = new UdpConnector(Ordering.Unordered);
                conn.Start();
                try
                {
                    ITransport t = conn.Connect("127.0.0.1", "9999", new Dictionary<string, string>());
                    Assert.AreEqual(Ordering.Unordered, t.Ordering);
                }
                catch (CannotConnectException) { Assert.Fail("Should have worked"); }
                finally { conn.Dispose(); }

                conn = new UdpConnector(Ordering.Sequenced);
                conn.Start();
                try
                {
                    ITransport t = conn.Connect("127.0.0.1", "9999", new Dictionary<string, string>());
                    Assert.AreEqual(Ordering.Sequenced, t.Ordering);
                }
                catch (CannotConnectException) { Assert.Fail("Should have worked"); }
                finally { conn.Dispose(); }
            }
            finally
            {
                if (acceptorThread != null) { acceptorThread.Abort(); }
                if (acc != null) { acc.Dispose(); }
            }
        }
Beispiel #2
0
 public void TestDualUdpAcceptors()
 {
     UdpAcceptor acc1 = new UdpAcceptor(IPAddress.Any, 9999);
     UdpAcceptor acc2 = new UdpAcceptor(IPAddress.Any, 9999);
     try
     {
         acc1.Start();
         try
         {
             acc2.Start();
             Assert.Fail("Should have thrown a transport error");
         }
         catch (TransportError) { /* do nothing */ }
     }
     finally
     {
         acc1.Dispose();
         acc2.Dispose();
     }
 }