// System.Net.Sockets.TcpListenerTest.cs // // Author: // Phillip Pearson (pp@myelin.co.nz) // // Copyright (C) 2001, Phillip Pearson // http://www.myelin.co.nz // using System; using System.Net; using System.Net.Sockets; using NUnit.Framework; namespace MonoTests.System.Net.Sockets { /// /// Tests System.Net.Sockets.TcpListener /// public class TcpListenerTest : TestCase { public TcpListenerTest(string name) : base(name) {} public static ITest Suite { get { return new TestSuite(typeof (TcpListenerTest)); } } /// /// Tests the TcpListener object /// (from System.Net.Sockets) /// public void test_TcpListener() { // listen with a new listener TcpListener inListener = new TcpListener(1234); inListener.Start(); // connect to it from a new socket Socket outSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); IPHostEntry hostent = Dns.GetHostByAddress("127.0.0.1"); IPEndPoint remote = new IPEndPoint(hostent.AddressList[0], 1234); outSock.Connect(remote); // make sure the connection arrives Assert(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