myahya
myahya

Reputation: 3171

GWT Returning Intermediate Result from Server to Client Ansynchronously

I am using GWT. My client collects data from the user and sends it to the server to perform a very length computation. The computation is composed of different stages. After each stage, I would like the server to send back the result to the client so that the user can see some progress, while the server continues with the remaining part of the computation.

What is an elegant way to do this (as little code as possible)?

Upvotes: 1

Views: 106

Answers (3)

p3nGu1nZz
p3nGu1nZz

Reputation: 1715

Comet is good for chat or other realtime application, but the simplest and easiest way to do this is to use to request that work in parrellel. The first request will POST data to the server to process. The second request will get the status of the processing job. This would be the async technique

Alternatively you could increment the process on the server side, and have the client POST data to the request at each stage. This way is a block technique; meaning that step 1 runs, and blocks step 2 until step 1 is done. This is a bit easier but the code is messier, as you will need to nest the three request inside each other's callback.

The main limitation COMET has is its issues with firewalls and ports. This can get pretty hairy, and also its QoS is not always 100% spot on. Sometimes requests dont get pushed in the right order or sometimes you dont always get the push. So for times where you need spot on accuracy using the async or blocking method work.

For refrence a majority of those fancy file uploaders use the async technique.

On the server side you will need to put in some static field that are stored in the session that will contain the update data to be sent to the client. In the client use a timer to specify the polling frequency to update the UI.

As for the request use a standard RPC request which basically just takes in a url of te servlet and then a callback.

Upvotes: 2

Yanflea
Yanflea

Reputation: 3934

I used the Atmosphere Websocket/comet framework for a project of mine. It is very easy to implement with GWT.

Upvotes: 1

Henrique Miranda
Henrique Miranda

Reputation: 994

You should use comet. Basically the server send notifications to the view, whenever you want. There are a lot of frameworks for gwt that can help you with that.

Upvotes: 2

Related Questions