[Mono-list] System.Net.TcpClient and IIS6?

rus rus@forgecom.co.uk
Wed, 08 Dec 2004 14:05:54 +0000


--=-TXr2z9gf4vA5/Jc2L57v
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all

I've been doing a little experiment with TcpClient (my first time ;))
and seem to have stumbled across a difference between mono and ms.NET
when talking to IIS6 servers.

I've attached the source below (apologies for bad code - it's just a
quick experiment to get used to the System.Net stuff)

If I do..
mono client.exe www.forgecom.info 80 "/"

under mono (1.0.4 on FC3), the output cuts out in the middle of the
response (not sure of the exact position (though it seems consistent).

under .NET (1.1 on windows 2000), the output is complete.  I've not
tested it using mono on win32, by the way.

I've compiled the source using the command:
mcs -t:exe -out:client.exe TcpClient.cs
under mono (1.0.4 on FC3) and run the same resulting exe on both
systems.

>From my tests so far, mono only seems to have a problem when talking to
IIS6. IIS5 and apache seem ok!

Is this a bug or am I missing something?


Cheers,
Rus.





--=-TXr2z9gf4vA5/Jc2L57v
Content-Disposition: attachment; filename=TcpClient.cs
Content-Type: text/x-csharp; name=TcpClient.cs; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

class MyClient
{

	public static void Main(string[] args)
	{
		string host = args[0];
		Int32 port = Convert.ToInt32(args[1]);
		string request = String.Format("GET {0} HTTP/1.1\r\nHost: {1}\r\nConnection: Close\r\n\r\n", args[2], host);

		Console.WriteLine("host={0}, port={1}, request={2}", host, port, request);

		string result = Get(host, port, request);
		Console.WriteLine(result);
	}
	
	public static string Get(string Hostname, Int32 Port, string request) {
		string result = "";
		int bufferSize;
		
		TcpClient client = new TcpClient(Hostname, Port);
		NetworkStream net = client.GetStream();
		using(client) {
			Byte[] sendBytes = Encoding.ASCII.GetBytes(request);
			net.Write(sendBytes, 0, sendBytes.Length);

			byte[] readBytes;
			do {
				bufferSize = client.ReceiveBufferSize;
				readBytes = new byte[bufferSize];
				net.Read(readBytes, 0, bufferSize);
				result += Encoding.ASCII.GetString(readBytes);
			} while(net.DataAvailable);
		}
		net.Close();
		client.Close();
		
		return(result);
	}
}


--=-TXr2z9gf4vA5/Jc2L57v--