-
Persistent connections
Hello, I have a questiona about how to manage persistent connections (HTTP1.1)
Once I have accepted a client, I create a new thread to recv/send data from/to client. To do that I suppose I have to run an infinite loop since the client closes the connection; if not, how can it be a persistent connection?
Code:
struct _INFOCS
{
SOCKET c;
SOCKET s;
};
unsigned _stdcall procClient(void *pvoid)
{
struct _INFOCS *ics=(struct _INFOCS*)pvoid;
while(1)
{
recv();
(if client wants to close) -> break loop;//that line is what I can't imagine
operations();
send();
}
ExitThread(0);
}
(NOTE: the struct _INFOCS have the sockets of the client and the server setted up on the accept action). I suppose that should be right, no? With that skeleton I have a persistent connection.
The problem is that the comercial navigators (I have tested it with nsn,ff,msie) never send the instruction to close the connection: the server always receives an http header with 'Connection: keep-alive' and 'Keep-Alive: x' (where 'x' is a number of seconds to wait till close the connection).
Does it mean that I have to create a timer to close the connection with the 'keep-alive' value? If yes, I have to update that timer with each recv of 'keep-alive', no?
I have read on the w3c that persistent connections doesn't allow idle connections, but how can I know what's an iddle connection if the request have a keep-alive=300 seconds (5 minutes)?
Thank's in advance
Niara
-
Ups, sorry; can it be moved to the networking area, please? Thank's.
Niara
-
You may want to look into using WinHTTP.
(also, for thread moving, use Fedex; they're soooo much better than the guys in brown :D)
-
Hello @nthony, thank's for your time and the link; let me take a look at it.
Niara
-
To use it I have to download the Microsoft® Windows Server 2003 SP1 Platform SDK - April 2005 Edition. I'm not sure that it includes de linking libraries *.a for DevC++, but I can remember that someday in somewhere I found some utility to convert *.lib to *.a
One last question: who are the guys in brown?
Niara
-
>I'm not sure that it includes de linking libraries *.a for DevC++, but I can remember that someday in somewhere I found some utility to convert *.lib to *.a
hmm you're right, it appears that MingW does not have a libwinhttp.a library... but from this discussion it would appear that it does have some sort of utility to convert between the two.
On the other hand, you could also try looking for the functionality you seek in the older Windows Internet API, WinInet.
>One last question: who are the guys in brown?
>Ups, sorry; can it be moved to the networking area, please? Thank's.
Never mind me, I was just being overly facetious :D
-
Hello @nthony, finally I get the joke :)
I opted to not use the WinHTTP libraries; instead of that I have found over the net some information about thread pools, in the mode of timeout based thread pools.
About the WinINet I have found that WinHTTP is similar ti wininiet except that it provides new functionality such as HTTP1.0 protocol support plus persistent connections management, and HTTP1.1 protocol suport plus chunked transfer.
I'll have to take a deeper look at it; the good and bad thing is that there's very lot of information. Maybe finaly I'll instal the winhttp libs.
Niara