// System.Net.Sockets.TcpListenerTest.cs // // Authors: // Phillip Pearson (pp@myelin.co.nz) // Martin Willemoes Hansen (mwh@sysrq.dk) // Gonzalo Paniagua Javier (gonzalo@ximian.com) // // (C) Copyright 2001 Phillip Pearson (http://www.myelin.co.nz) // (C) Copyright 2003 Martin Willemoes Hansen (mwh@sysrq.dk) // (c) 2003 Ximian, Inc. (http://www.ximian.com) // using System; using System.Net; using System.Net.Sockets; using NUnit.Framework; namespace MonoTests.System.Net.Sockets { [TestFixture] public class TcpListenerTest { [Test] public void TcpListener () { // listen with a new listener (IPv4 is the default) TcpListener inListener = new TcpListener (8766); inListener.Start(); // connect to it from a new socket IPHostEntry hostent = Dns.GetHostByAddress (IPAddress.Loopback); Socket outSock = null; foreach (IPAddress address in hostent.AddressList) { if (address.AddressFamily == AddressFamily.InterNetwork) { /// Only keep IPv4 addresses, our Server is in IPv4 only mode. outSock = new Socket (address.AddressFamily, SocketType.Stream, ProtocolType.IP); IPEndPoint remote = new IPEndPoint (address, 8766); outSock.Connect (remote); break; } } // make sure the connection arrives Assert.IsTrue (inListener.Pending ()); Socket inSock = inListener.AcceptSocket (); // now send some data and see if it comes out the other end const int len = 1024; byte[] outBuf = new Byte [len]; for (int i=0; i