I didn't find any problem in your code:
TcpClient oTcpClient = new TcpClient();
IAsyncResult oIAsyncResult = oTcpClient.BeginConnect("www.daniweb.com", 80, null, null);
bool success = oIAsyncResult.AsyncWaitHandle.WaitOne(5000, true);
if (!success)
{
oTcpClient.Close();
Console.WriteLine("Timeout...");
return;
}
oTcpClient.EndConnect(oIAsyncResult);
NetworkStream oNetworkStream = oTcpClient.GetStream();
StreamReader oStreamReader = new StreamReader(oNetworkStream);
StreamWriter oStreamWriter = new StreamWriter(oNetworkStream);
oStreamWriter.AutoFlush = true;
oStreamWriter.Write("GET /forums/thread208224.html HTTP/1.1\r\n"
+ "Host: www.daniweb.com\r\n"
+ "User-Agent: Mozilla/5.0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
string output = "";
string src = "";
while (output != null)
{
output = oStreamReader.ReadLine();
if (output != null)
{
src += output;
}
}
Console.WriteLine(src);
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
Offline 6,527 posts
since Oct 2008