1 // System.Net.Sockets.TcpClientTest.cs
4 // Phillip Pearson (pp@myelin.co.nz)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 // (C) Copyright 2001 Phillip Pearson (http://www.myelin.co.nz)
8 // (C) Copyright 2003 Martin Willemoes Hansen
13 using System
.Net
.Sockets
;
14 using NUnit
.Framework
;
16 namespace MonoTests
.System
.Net
.Sockets
{
19 /// Tests System.Net.Sockets.TcpClient
22 public class TcpClientTest
{
25 /// Tests the TcpClient object
26 /// (from System.Net.Sockets)
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));
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();
48 byte[] outBuf
= new Byte
[len
];
49 for (int i
=0; i
<len
; i
++)
51 outBuf
[i
] = (byte)(i
% 256);
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
]);