public void Test_Ops()
        {
            SocketWatcher w = new SocketWatcher(20);
            Address a = new Address("127.0.0.1", 7002);
            a.Resolve();
            AsyncSocket one = w.CreateListenSocket(this, a);
            AsyncSocket two = null;
            AsyncSocket three = one;
            AsyncSocket four = two;
            Assert.IsTrue(one == three);
            Assert.IsTrue(two == four);
            Assert.IsTrue(one >= three);
            Assert.IsTrue(two >= four);
            Assert.IsTrue(one <= three);
            Assert.IsTrue(two <= four);
            Assert.IsTrue(one != two);
            Assert.IsTrue(two != one);
            Assert.IsTrue(one > two);
            Assert.IsTrue(one >= two);
            Assert.IsTrue(two < one);
            Assert.IsTrue(two <= one);

            two = w.CreateListenSocket(this, a);
            four = two;
            Assert.IsTrue(one == three);
            Assert.IsTrue(two == four);
            Assert.IsTrue(one >= three);
            Assert.IsTrue(two >= four);
            Assert.IsTrue(one <= three);
            Assert.IsTrue(two <= four);
            Assert.IsTrue(one != two);
            Assert.IsTrue(two != one);

            int c = ((IComparable)one).CompareTo(two);
            Assert.IsTrue(c != 0);
            if (c == -1)
            {
                // one less than two
                Assert.IsTrue(one < two);
                Assert.IsTrue(one <= two);
                Assert.IsTrue(two > one);
                Assert.IsTrue(two >= one);
            }
            else if (c == 1)
            {
                // one greater than two
                Assert.IsTrue(one > two);
                Assert.IsTrue(one >= two);
                Assert.IsTrue(two < one);
                Assert.IsTrue(two <= one);
            }
            else
            {
                Assert.IsTrue(false);
            }
            one.Close();
            two.Close();
        }
        [Test] public void Test_Write()
        {
            SocketWatcher w = new SocketWatcher(20);
            Address a = new Address("127.0.0.1", 7001);
            a.Resolve();

            AsyncSocket listen = w.CreateListenSocket(this, a);
            listen.RequestAccept();

            AsyncSocket connect;
            lock (done)
            {
                connect = w.CreateConnectSocket(this, a);
                bool NoTimeout = Monitor.Wait(done, new TimeSpan(0, 0, 30));

                Assert.IsTrue(NoTimeout, "The read command didn't complete in time.");
                Assert.IsTrue(succeeded, errorMessage);
            }

            Assert.AreEqual("5678901234", success);
            connect.Close();
            listen.Close();
        }
        public void Test_Full_Response()
        {
            SocketWatcher watcher = new SocketWatcher();
            Address a = new Address("127.0.0.1", 7002);
            a.Resolve();

            ServerListener server = new ServerListener();
            AsyncSocket server_sock = watcher.CreateListenSocket(server, a);
            server_sock.RequestAccept();

            ResponseListener resp = new ResponseListener();
            HttpSocket sock = new HttpSocket(resp);

            Uri u = new Uri("http://localhost:7002/");
            byte[] buf = ENC.GetBytes("11111");
            HttpSocket s = (HttpSocket)sock;
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("1234567890", resp.Last);

            resp.Last = null;
            buf = ENC.GetBytes("22222");
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("1234567890", resp.Last);

            resp.Last = null;
            buf = ENC.GetBytes("33333");
            s.Execute("GET", u, buf, 0, buf.Length, "text/plain");
            resp.Event.WaitOne();
            Assert.AreEqual("12345678901234567890", resp.Last);
        }
 /// <summary>
 /// Outbound connection.  Eventually calls Listener.OnConnect() when
 /// the connection comes up.  Don't forget to call RequestRead() in
 /// OnConnect()!
 /// </summary>
 /// <param name="addr"></param>
 public override void Connect(Address addr)
 {
     // Debug.WriteLine("starting connect to " + addr.ToString());
     State = SocketState.Resolving;
     if (m_synch)
     {
         addr.Resolve();
         OnConnectResolved(addr);
     }
     else
     {
         addr.Resolve(new AddressResolved(OnConnectResolved));
     }
 }