private void SimpleTestInstance(string testString, int port)
{
// Open a socket to the server
TcpClient client = new TcpClient("localhost", port);
Socket socket = client.Client;
// This is the string we expect to get back
String expectedString = "Welcome!\r\n" + testString.ToUpper();
// Convert the string into an array of bytes and send them all out.
// Note the use of the synchronous Send here. We can use it because
// we don't care if the testing thread is blocked for a while.
byte[] outgoingBuffer = encoding.GetBytes(testString);
socket.Send(outgoingBuffer);
// Read bytes from the socket until we have the number we expect.
// We are using a blocking synchronous Receive here.
byte[] incomingBuffer = new byte[encoding.GetByteCount(expectedString)];
int index = 0;
while (index < incomingBuffer.Length)
{
index += socket.Receive(incomingBuffer, index, incomingBuffer.Length - index, 0);
}
// Convert the buffer into a string and make sure it is what was expected
String result = encoding.GetString(incomingBuffer);
Assert.AreEqual(expectedString, result);
}