(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System / Test / System.Net.Sockets / TcpClientTest.cs
blobba8884386067a6fecaf23c9b1fd96533a7d37a57
1 // System.Net.Sockets.TcpClientTest.cs
2 //
3 // Authors:
4 // Phillip Pearson (pp@myelin.co.nz)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 //
7 // (C) Copyright 2001 Phillip Pearson (http://www.myelin.co.nz)
8 // (C) Copyright 2003 Martin Willemoes Hansen
9 //
11 using System;
12 using System.Net;
13 using System.Net.Sockets;
14 using NUnit.Framework;
16 namespace MonoTests.System.Net.Sockets {
18 /// <summary>
19 /// Tests System.Net.Sockets.TcpClient
20 /// </summary>
21 [TestFixture]
22 public class TcpClientTest {
24 /// <summary>
25 /// Tests the TcpClient object
26 /// (from System.Net.Sockets)
27 /// </summary>
28 [Test]
29 public void TcpClient()
31 // set up a listening Socket
32 Socket lSock = new Socket(AddressFamily.InterNetwork,
33 SocketType.Stream, ProtocolType.Tcp);
35 lSock.Bind(new IPEndPoint(IPAddress.Any, 1234));
36 lSock.Listen(-1);
39 // connect to it with a TcpClient
40 TcpClient outClient = new TcpClient("localhost", 1234);
41 Socket inSock = lSock.Accept();
44 // now try exchanging data
45 NetworkStream stream = outClient.GetStream();
47 const int len = 1024;
48 byte[] outBuf = new Byte[len];
49 for (int i=0; i<len; i++)
51 outBuf[i] = (byte)(i % 256);
54 // send it
55 stream.Write(outBuf,0,len);
57 // and see if it comes back
58 byte[] inBuf = new Byte[len];
59 int ret = inSock.Receive(inBuf, 0, len, 0);
60 Assertion.Assert(ret != 0);
62 for (int i=0; i<len; i++)
64 Assertion.Assert(inBuf[i] == outBuf[i]);
68 // tidy up
69 inSock.Close();
70 outClient.Close();
71 lSock.Close();