Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Terminate connection on long polling
Message
From
29/03/2021 12:14:08
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Terminate connection on long polling
Miscellaneous
Thread ID:
01679323
Message ID:
01679323
Views:
82
Shop has customer display connected to 192.168.1.68 on LAN.
It uses long polling to recevice display data using http POST.

It displays sent data but it takes 5 sends for HttpSendRequest to return. I set timeouts to 60 ms and number of retries to 1 but it still takes 5 seconds before HttpSendRequest terinates with 12002 winsocket error as expected.
I timeout has bigger value HttpSendRequest waits longer time as expcected.
Howver it seems that it cannot wait less that 5 seconds for unknown reason.

How to terminate call immendiately after data is sent so that single threaded application can continue. Command

curl -d "@duedata.json" -H "Content-Type: application/json; charset=utf-8" --max-time 2 -X POST http://192.168.1.92:8082/poll-command

takes 2 seconds and shows data in PCU. Dats sending takes 1.2 seconds.
    FUNCTION HTTPGetEx
    LPARAMETERS tcPage, tcBuffer, tnBufferSize, tcHeaders, tcFileName, lpost
    
    
    DECLARE INTEGER HttpOpenRequest ;
       IN WININET.DLL ;
       INTEGER hHTTPHandle,;
       STRING lpzReqMethod,;
       STRING lpzPage,;
       STRING lpzVersion,;
       STRING lpzReferer,;
       STRING lpzAcceptTypes,;
       INTEGER dwFlags,;
       INTEGER dwContextw
    
    hHTTPResult=HttpOpenRequest(THIS.hhttpsession,;
       Icase(VARTYPE(lpost)='C', lpost, lpost or  tnPostSize > 0, "POST","GET"),;
       tcPage,;
       NULL,NULL,NULL,;
       INTERNET_FLAG_RELOAD + ;
       IIF(THIS.lsecurelink,INTERNET_FLAG_SECURE,0) + ;
       this.nHTTPServiceFlags,0) 
    
    *** Apply timeout to the HTTP connection handle
    THIS.wininetsettimeout(THIS.nConnectTimeOut,hHTTPResult)
    THIS.wininetsettimeout(THIS.nConnectTimeOut)
    
    THIS.hhttpsession=hHTTPResult
    
    DECLARE INTEGER HttpSendRequest    ;
       IN WININET.DLL ;
       INTEGER hHTTPHandle,;
       STRING lpzHeaders,;
       INTEGER cbHeaders,;
       STRING lpzPost,;
       INTEGER cbPost
    
    dwTimeoutSecs = 60
    
    llRetVal=InternetSetOption(hHTTPResult,;
       INTERNET_OPTION_RECEIVE_TIMEOUT,;
       @dwTimeoutSecs,4)
    
    llRetVal=InternetSetOption(hHTTPResult,;
       INTERNET_OPTION_SEND_TIMEOUT,;
       @dwTimeoutSecs,4)
    
    
    dwTimeoutSecs=1  &&// Retry only 1 time
    llRetVal=InternetSetOption( hHTTPResult,;
          INTERNET_OPTION_CONNECT_RETRIES,;
          @dwTimeoutSecs,4)
    
    ? 'Before HttpSendRequest'
    * Todo: why HttpSendRequest takes 5 seconds ?
    lnRetval=HttpSendRequest(hHTTPResult,tcHeaders,LEN(tcHeaders),lcPostBuffer,tnPostSize)
    ? 'After HttpSendRequest'
Andrus
Next
Reply
Map
View

Click here to load this message in the networking platform