Example #1
0
        public void TestUdpNegotiationTimeout()
        {
            UdpClient serverSocket = new UdpClient(9999);
            UdpConnector conn = new UdpConnector();

            try {
                conn.Start();
                try
                {
                    conn.Connect("127.0.0.1", "9999", new Dictionary<string, string>());
                    Assert.Fail("Should have timed out");
                } catch(CannotConnectException e)
                {
                    // expected
                }
            } finally
            {
                serverSocket.Close();
                conn.Dispose();
            }
        }
Example #2
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(); }
            }
        }