How to receive push notifications using Indy?

I have a device that uses soothing web services, and I used its request / response function, as a result of which I send it a command through an HTTP GET and responds with the appropriate XML.

Now I need to use pus device alerts. I tried the same approach as above when I supply the TIdHTTP.Get procedure with the corresponding HTTP URL and the stream that the response is placed in, but this does not seem to work. The call to Get does not return. This makes sense to me in that with push notifications you open the HTTP communication stream between the device and the program, and this connection will remain open for streaming until it is closed.

My problem, although I do not know how to get the XML from the stream, if the Get method does not return. It is as if the program crashed. I tried passing a message through a GET with the device and reading the stream to the stream so that this could continue on its own, and then my main application could just check the resulting XML, but that would not work either.

I am wondering if I am complicating this, and if there is a simple solution. When I just send a request and get a response, it works great; it's just streaming that I can't work with.

If I use the URL in Internet Explorer, I can see the returned XML, as well as the constantly loaded logo indicating that the stream is open.

I ran the command through my Firefox Mozilla 20.0.1 browser and saw that wirehark captures the push request and response. The HTTP part is shown below:

 GET /elite/notifications/stream?resume=2013-05-06T00:00:00Z HTTP/1.1 Host: 192.168.10.10 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive 

The request I'm trying to do in Delphi is as follows:

 if fEventStream = nil then fEventStream := TStringStream.Create(''); try TapItem.fHTTP.Get(TapItem.I2IReaderIP+'/elite/notifications/stream?resume=2013-05-01T00:00:00Z',fEventStream); TapItem.fEventXML := fEventStream.ReadString(fEventStream.Size); except on e:exception do begin ShowMessage(e.message) end; end; 

I also tried using TidTCPConnection

  fTCPConn.IOHandler.Writeln(TapItem.I2IReaderIP+I2I_PUSH_EVENT+'2013-05-01T00:00:00Z'); While not Terminated do begin XMLString := XMLString + fTCPConn.IOHandler.Readln; end; 

Any help in this matter would be appreciated.

DECISION


In my case, just adding the GET keyword to the start of the call made. I suggested that the TCP Connection component requires knowing what action (i.e. GET PUT, etc.) you want to do, it cannot read my mind, it makes sense

 fTCPConn.IOHandler.Writeln('GET ' + TapItem.I2IReaderIP+I2I_PUSH_EVENT+'2013-05-01T00:00:00Z'); While not Terminated do begin XMLString := XMLString + fTCPConn.IOHandler.Readln; end; 
+7
source share
2 answers

TIdHTTP does not currently support push servers (and even then there are several ways that push servers can be implemented - which one is your REST service using?). You will need to go to TIdTCPClient , format and send the HTTP request manually, and then use a timer or stream to read and analyze pending responses as they arrive.

+3
source

The HTTP client (TIdHTTP) on the Indy 10.6 trunk now also supports "Server Push" if the server sends a multipart/... response:

New TIdHTTP flag hoNoReadMultipartMIME

A new flag hoNoReadMultipartMIME has been added to the TIdHTTP.HTTPOptions Property. The purpose of this flag is to indicate whether TIdHTTP should read the contents of the body "multipart / ..." responses, such as "multipart / x-mixed-replace" or "multipart / byteranges", in the target TStream or exit immediately and allow the person to read the contents manually .

Since there are many ways to implement Server Push, this answer may be more or less useful for a given server.

0
source

All Articles