sockets and http question

G

Guest

im having a small bug now where if i give a http header GET / with a
connection: keep-alive i cant tell when the server is done sending. If i say
connection: close i dont have a problem. Here is breifly my code.

remember this works fine if i say Connection: close in the http header, if i
say keepalive it does not. anyone know why?

asynch send
------------------------
client.BeginSend(byteData, 0, byteData.Length, 0, new
AsyncCallback(SendCallback), client);


receive event
--------------
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
//more packets
state.sb.Append(Encoding.ASCII.GetString(state.buffer,0,bytesRead));
client.BeginReceive(state.buffer,0,StateObject.BufferSize,0, new
AsyncCallback(ReceiveCallback), state);
}
else
{
if (state.sb.Length > 1)
{ //its done
response = state.sb.ToString();
receiveDone.Set();
}
}
 
G

Guest

im not using either im using system.net sockets lowest level the framework
will let me

Joerg Jooss said:
Michael said:
im having a small bug now where if i give a http header GET / with a
connection: keep-alive i cant tell when the server is done sending.
If i say connection: close i dont have a problem. Here is breifly my
code.

remember this works fine if i say Connection: close in the http
header, if i say keepalive it does not. anyone know why?
[snip]

Question: Why are you using TcpClient instead of WebRequest? This means
you must also implement all low-level TCP connection handling
faithfully according to the HTTP spec, which might be the problem here.

Cheers,
 
J

Joerg Jooss

Michael said:
im not using either im using system.net sockets lowest level the
framework will let me

Ah, guessed wrong ;-)

The question remains, though -- why?

Cheers,
 
J

Joerg Jooss

Michael said:
how about why not? i have microsofts pre made object but was having
trouble with cookies etc see
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?que
ry=httpwebresponse+evanchik&dg=&cat=en_US_850c4b7a-113f-45f2-93ff-9d21
e03b29f3&lang=en&cr=&pt=&catlist=&dglist=&ptlist=&exp=&sloc=en-us

OK, now I do remember that thread ;-)

But what about the code I posted? No good?

also my question kind of got answered here
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sh
arp/Q_21437151.html#14090121

what do you think?

That this doesn't answer anything. And that this is only shows the
complexity of what you need to deal with if you try this stuff at
socket level.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top