Jump to content
Sign in to follow this  

Autoit client for Real Time Push Notification using Long-Polling

Recommended Posts


Thanks for your time reading this. I had searched the forum but can't seems to find a way to do this.
I also searched extensively in the internet trying to implement using other approaches but did not get it work

or too difficult for my level using .

I am trying to implement push notification from a web server using long-polling like https://github.com/panique/php-long-polling,

except that the client is originated from autoit.

I think this will be extremely useful for autoit community to implement real-time push notification if it is working.

i.e. we can automate autoit in any PC whenever there is status change at the server, in near real time without

the load.

Here's what i have:

1. Currently, my autoit client in my PC at every 1 min, sends HTTP request with previously checked job_id to the apache server

and the server will check if there is a new job_id for this client. If there is, server returns 1 and autoit client starts to do several processes locally.

If return 0,  do nothing. 

Sometimes it can take longer for the client to get notified due to the polling cycle at every 1 min.

2. I read that using long-polling method, the web client can get almost instant update and
i tested the script above from github with desired result.

When the data at the server changes, it instantly reflects on the web browser on my PC. 

But that is only possible if i use a web browser as client. How to do using autoit as client?

Ideally using long-polling approach, the autoit client should be able to send a HTTP GET/Post to the Server,
STAY CONNECTED for the session until there is new data from the server. 

When new data is available, the server return with 1 and the connection is closed.

This way, it will reduce the load and traffic without fixed interval polling from the client. 

I tested an autoit http request function and it is able to retrieve data from server BUT the connection will close 

after the request is served. According to long-polling approach, the connection should stay until there is NEW data available

from the server.

How to do this in Autoit? 


The test function to check server as follows: 

Func check_post_internet()

$oWinHttpRequest = ObjCreate("winhttp.winhttprequest.5.1")
 $oWinHttpRequest.Open("POST", "http://www.myweb.com/server/index.php", False)
$oWinHttpRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$msg = "last_news_id=115&client_id=112"
If $oWinHttpRequest.Status <> 200 Then
   MsgBox(0, "HTTP Request Error", "Error code: " & $oWinHttpRequest.Status & " " & $oWinHttpRequest.ResponseText)
  $returnData = $oWinHttpRequest.ResponseText
  MsgBox(0, "HTTP Post Example", $returnData)
EndFunc   ;==>check_post_internet



1. Can the above be modified to have the connection stay with the server until data arrive?

2. If not possible to implement above, how about running an external program that act as a long polling desktop client?

what desktop client can be use? Can Command line curl for windows at http://curl.haxx.se/download.html? 

Tested Curl.exe but again, the connection does not stay. May be i am not aware of syntax used. 

I tried some of the autoit TCP client-server scripts but prefer the long-polling approach describe.

Many thanks again if you guys can offer any advice.



Share this post

Link to post
Share on other sites

It is ok. I was told by the curl developer that basically nothing need to be done at the client end and if need to add extend the keep alive time.

This topic is closed.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...