Re: winsock revc / send by William
William
Tue Jul 29 15:39:24 CDT 2003
"Calvin" <pk@pk.com> wrote in message
news:Of9#7bZVDHA.1676@TK2MSFTNGP10.phx.gbl...
> i am trying to connect to a http with winsock, i have successfully connect
> to a server with connect,
> but if i want to receive back the server response, what function i should
> use ?
You use one or more of calls to recv().
Using a single call is problematic, because in general you don't know how
much data you are going to get and you don't know how the network stack is
going to return it to you. But you do know that the data is preceded by HTTP
headers which are terminated by a blank line - two consecutive end of line
markers - "\r\n\r\n". So, you need to keep reading until you get at least
that much.
When you have the header, you can look for a "Content-length" header (I am
not sure of the capitalization, I don't have the HTTP spec in reach now). If
you find it, that is the count of bytes past the end of the blank line. You
just keep receiving until you have all the data. If you don't have a length
header, you keep trying until recv() fails by returning a count that is less
than 1.
That answers the question you asked. However, it doesn't answer the question
"Why do you want to do this?". :-) Chances are that it would be a lot easier
to use functions from the WinInet or WinHttp libraries or even (shudder)
something based on COM. :-)
Regards,
Will