views:

99

answers:

1

I need to program a stateless server to execute remote methods. The client uses REST with a JSON parameter to pass the method name and its parameters. After servicing the result the session is closed. I have to use Indy10, TCP/IP as protocol, and therefore look at using IdHTTPServer.

Large result sets are chunked by Indy10 and sent to the client in parts.

My problem now is:

The methods on the server provide progress information if they take longer to produce the results. These are short messages. How can I write back to the client?

So far I have used writeflush on the server, but the client waited for the request to end before handing back the full resultset, including the progress information. What can I do to display/process such progress information on the client and yet keep the connection open to receive further data on the same request?

+1  A: 

On the client side instead of the regular HTTP client component TIdHTTP you can instead use Indy class TIdTCPClientCustom in unit IdTCPClient to send the request and process the response.

This class gives total control over the processing of the server responses. I used the TIdTelnet class as a starting point to implement a client for a message broker messaging protocol, and found it stable and reliable for both text and binary data.

In the receiving thread, the incoming data can be read up to delimiters and parsed into chunks (for the progress information) and immediately processed.

mjustin
I need to use TIdHTTPServer, as I am implementing REST (a GET with parameters from TIdHTTP). I would love to use something like writebufferflush, but I don't get it to work - I always get the first writeln in a messagebox, and then the rest is discarded.
Ralph Rickenbach
See my edit, my suggestion is to use TIdTCPClientCustom on the client side instead of TIdHTTP, to have total control over the processing of the server response
mjustin