简体   繁体   中英

How does my application detect a premature disconnect by a client?

When I debug my server application that uses Restlet, the client (which is a mobile app) throws a TimeoutException, not getting the data, but my server application doesn't know. The application assumes the client has received its data. How can my application detect that the client did not get the data?

The use case is not debugging, but I can imagine that a server may be slow enough for the client to throw a timeout exception, or other causes of premature disconnect that the server app doesn't notice.

One path I can take is to build in application-level acknowledgement of received data. But that makes my application more complicated.

You can't, but you also shouldn't have to. If the client didn't get the data, then it can always ask again. RESTful protocols really have to support this kind of thing.

For example, if the client does a POST that performs some operation, then it must be able to either:

1) Re-POST the same data, to perform the operation only if it hasn't already been done , and return the response data that it may have missed before. This is often accomplished with some kind of transaction ID generated on the client, or on the server in a previous request; or

2) Check to see if the operation succeeded, and retry if it didn't, or re-request the response data if it did. Again some kind of previously-established transaction ID is often required for this.

Also, if you can get into a situation where an actual user is unsure about whether some operation has completed successfully, there needs to be some UI that he can visit to check its status.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM