开发者

Progress feedback in stateless HTTP session

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 displ开发者_运维问答ay/process such progress information on the client and yet keep the connection open to receive further data on the same request?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜