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;