G
Guest
Hello-
I'm trying to create a console app that will accept an incoming HTTP request
and output the information of the request to the console. The code is pretty
simple - here's what it looks like:
TcpListener listenter = new TcpListener(IPAddress.Any, 8000);
listenter.Start();
Socket socket = listenter.AcceptSocket();
byte[] buffer = new byte[32];
int bytesReceived = 0;
while( (bytesReceived = socket.Receive(buffer, 0, buffer.Length,
SocketFlags.None)) > 0 )
{
Console.Write(Encoding.ASCII.GetString(buffer));
}
socket.Close();
The response I get looks like this:
GET / HTTP/1.1
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
2.0
..50727; .NET CLR 1.1.4322)
Host: localhost:8000
Connection: Keep-Alive
8000
Connectio
The problem is that the application is hanging after it finished outputting
"Connectio". I had expected the output to end earlier, after the Keep-Alive
header.
Does anyone know why the app might be hanging here?
Regards-
Eric
I'm trying to create a console app that will accept an incoming HTTP request
and output the information of the request to the console. The code is pretty
simple - here's what it looks like:
TcpListener listenter = new TcpListener(IPAddress.Any, 8000);
listenter.Start();
Socket socket = listenter.AcceptSocket();
byte[] buffer = new byte[32];
int bytesReceived = 0;
while( (bytesReceived = socket.Receive(buffer, 0, buffer.Length,
SocketFlags.None)) > 0 )
{
Console.Write(Encoding.ASCII.GetString(buffer));
}
socket.Close();
The response I get looks like this:
GET / HTTP/1.1
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
2.0
..50727; .NET CLR 1.1.4322)
Host: localhost:8000
Connection: Keep-Alive
8000
Connectio
The problem is that the application is hanging after it finished outputting
"Connectio". I had expected the output to end earlier, after the Keep-Alive
header.
Does anyone know why the app might be hanging here?
Regards-
Eric