All pastes #407063 Raw Edit

Mine

public text v1 · immutable
#407063 ·published 2007-03-22 21:29 UTC
rendered paste body
using System;
using System.Net.Sockets;
using System.IO;

namespace GrabPageClient
{
	class GrabPageClient
	{
		static void Send(string message, NetworkStream NetIO)
		{
			char[] theMessage;
			theMessage = message.ToCharArray();
			for ( int i = 0; i < theMessage.Length; i++ ) NetIO.WriteByte( (byte) theMessage[i] );
		}

		static void Main()
		{
			TcpClient client = null;
			string hostname = "";
			int port = 80;
			NetworkStream netIO = null;

			Console.Write("\r\nEnter server hostname or IP address (. to end): ");
			hostname = Console.ReadLine();

			while (hostname != ".") 
			{						
				try
				{ 	
					Console.WriteLine( "Attempting connection..." );
					client = new TcpClient();

					client.Connect( hostname, port );
					Console.WriteLine( "\r\nConnected to Web server at " + hostname );	

					netIO = client.GetStream();
					Console.WriteLine( "\r\nGot I/O streams." );				

					try
					{	
						Send("GET / HTTP/1.0 \r\n\r\n", netIO);
						Console.WriteLine("Sent request..\r\n");

						int c = 0;
						while ( c != -1 )
						{
							c = netIO.ReadByte();
							Console.Write(((char) c).ToString());
						}

					}
					catch ( Exception )
					{
						Console.WriteLine("\r\nThe server stopped the connection!");
						System.Environment.Exit( System.Environment.ExitCode );
					}
				}
				catch ( Exception )
				{
					Console.WriteLine( "\r\n" );
				}			

				netIO.Close();
				client.Close();

				Console.Write("\r\nEnter server hostname or IP address (. to end): ");
				hostname = Console.ReadLine();
			}
		}
	}
}