1 // System.Net.Sockets.TcpListenerTest.cs
4 // Phillip Pearson (pp@myelin.co.nz)
6 // Copyright (C) 2001, Phillip Pearson
7 // http://www.myelin.co.nz
12 using System.Net.Sockets;
13 using NUnit.Framework;
15 namespace MonoTests.System.Net.Sockets {
18 /// Tests System.Net.Sockets.TcpListener
20 public class TcpListenerTest : TestCase {
22 public TcpListenerTest(string name) : base(name) {}
24 public static ITest Suite {
26 return new TestSuite(typeof (TcpListenerTest));
31 /// Tests the TcpListener object
32 /// (from System.Net.Sockets)
34 public void test_TcpListener()
36 // listen with a new listener
37 TcpListener inListener = new TcpListener(1234);
41 // connect to it from a new socket
42 Socket outSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
44 IPHostEntry hostent = Dns.GetHostByAddress("127.0.0.1");
45 IPEndPoint remote = new IPEndPoint(hostent.AddressList[0], 1234);
46 outSock.Connect(remote);
49 // make sure the connection arrives
50 Assert(inListener.Pending());
51 Socket inSock = inListener.AcceptSocket();
54 // now send some data and see if it comes out the other end
56 byte[] outBuf = new Byte[len];
57 for (int i=0; i<len; i++)
59 outBuf[i] = (byte)(i % 256);
62 outSock.Send(outBuf, 0, len, 0);
64 byte[] inBuf = new Byte[len];
65 int ret = inSock.Receive(inBuf, 0, len, 0);
68 // let's see if it arrived OK
70 for (int i=0; i<len; i++)
72 Assert(inBuf[i] == outBuf[i]);
76 // tidy up after ourselves