Persistent connections

This is a discussion on Persistent connections within the Networking/Device Communication forums, part of the General Programming Boards category; Hello, I have a questiona about how to manage persistent connections (HTTP1.1) Once I have accepted a client, I create ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287

    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

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Ups, sorry; can it be moved to the networking area, please? Thank's.

    Niara

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    You may want to look into using WinHTTP.
    (also, for thread moving, use Fedex; they're soooo much better than the guys in brown )

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Hello @nthony, thank's for your time and the link; let me take a look at it.

    Niara

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    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

  6. #6
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    >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

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Connections
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 06-16-2006, 11:12 AM
  2. Listing current connections
    By w4ck0z in forum Networking/Device Communication
    Replies: 4
    Last Post: 03-05-2005, 02:48 PM
  3. Select handling more then 500 connections
    By Chronom1 in forum Networking/Device Communication
    Replies: 5
    Last Post: 02-27-2005, 03:20 PM
  4. WinXP Network Connections pop-up
    By DavidP in forum Tech Board
    Replies: 1
    Last Post: 10-02-2002, 06:36 PM
  5. Multiple Client Connections
    By (TNT) in forum Windows Programming
    Replies: 1
    Last Post: 04-06-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21