Client side Callback in GWT

I'm trying to create a logger for a GWT application as an exercise to evaluate GWT. What I specifically want to do is have it so that I can post messages to a client side label at any point from the server side. So, if some interesting stuff has happened on the server the client can be updated.

My First question is, is this possible, I can understand it not being.

Second, if it is possible, where should I look for information, I've tried google and their documentation and all the showcases have nothing on this.


Asked by: John829 | Posted: 21-01-2022

Answer 1

Well, there are a couple of Options. You need to get the data from the server... So you either need to poll the server, or use server push.

Polling is pretty easy. Just use the Timer class to repeatedly call a service to see what value it should be displaying.

Server push is done using something like comet. here is one implementation for gwt that looks somewhat promising. They basic concept behind this is the browser sends a request to the server and keeps the connection open so the server is free to keep sending data back.

Comet is the better option if you can get it working. It will probably be simpler and scale better.

Good Luck!

Answered by: Kelvin118 | Posted: 22-02-2022

Answer 2

Polling is probably the best way to do what you're looking for. The big gotcha with GWT is that everything has to be serializable. I'm not sure if anything that can push to the browser can be easily serialized.

Answered by: Ted638 | Posted: 22-02-2022

Similar questions

java - RMI IIOP client object as callback

I'm trying to build rmi-iiop application (very simple chat). I need server to be able to communicate with client so my thinking was to create interface of connected user: public interface UserInterface extends Remote { public void receiveMessage(String message) throws RemoteException; } Then on client side create User class with methods server can execute('receiveMessage'): ...

java - EJB3 client callback?

For learning purposes as I'm new to EJB3, I'm implementing the board game Risk as a client-server app with EJB3 on the server side. The intention is that multiple users would log in and play a game together. For the moment, I'm thinking of using JSF for the frontend. There are multiple instances in which an action by some client 'A' needs to result in some other client 'B' being notified. E.g. if A attacks a countr...

Java callback function on every class method

Is there a way in JAVA to call a callback function on every method of my class without having to explicitly do the call?? I don't want to do public void foo() { //some code callBackFunction() } I would like to do public void foo() { //some code } and then the class recognizes that it has to call the callBackFunction()

Java RMI timeout in callback

We are using Java RMI for communication. An RMI client passes a processing request and an object with a callback method to an RMI server. The server invokes the callback when it is done with processing. The setup is similar to the one described in RMI Callbacks. Occasionally we are getting a "read time out" exce...

java - How to avoid memory leaks in callback?

Effective Java says: A third common source of memory leaks is listeners and other callbacks. If you implement an API where clients register callbacks but don’t deregister them explicitly, they will accumulate unless you take some action. The best way to ensure that callbacks are garbage collected promptly is to store only weak references to them, for instance, by storing them on...

java - Android GPS Callback off UI Thread

I'm having trouble getting the GPS's onLocationChanged to run on a different thread. I understand how to manage UI thread when I'm calling a function but with the GPS, I don't actively call the function. My intent is to have a light flash every time the GPS receives a reading. I have put this function in a Runnable. I passed this function to a class that implements LocationListener. Then in the main class, I start...

could anybody please explain what is callback method with some sample example in java?

could anybody please explain what is callback method with some sample example in java?

java - var values argued into a callback from outside it:

Eclipse redlines width, height, width, height in the doSomething() arg list in the callback. Little red X in the left margin; says: Multiple markers at this line - Cannot refer to a non-final variable height inside an inner class defined in a different method - Cannot refer to a non-final variable width inside an inner class defined in a different method - Cannot refer to a non-final ...

visual c++ - Callback to Java method from c++

Here is my situation and it's a bit complicated, but it has to be this way. I'm implementing a program from Java that open an application by using JNative. The application is written in C++. But when the application is finished I want it to callback to Java to let Java knows that the run is finished. Can I do that and how? I know I should use JNI but I found no example about that. Thanks.

java - Nested Callback Handlers?

I am getting a set of data from the database where the query produces a repetition of data with a different "Special" value. For example the user "A" can be repeated twice, having three different "Special" values under the "Special Column". I am using a callback handler to retrieve the data and put it into a list, now additionally I want the Special column to have its own callback where for each user the specials l...

java - rmi callback gotchas?

What do I need to worry about when doing callbacks in RMI? I just need a simple client notification mechanism to avoid excessive polling. I found an online example and it looks pretty straightforward, the client just implements an interface that extends Remote (like the server does) and passes it to the server, which can...

Java: Apply Callback to Array Values

I'm looking for a simple way to apply a callback method to each element in a String array. For instance in PHP I can make all elements in an array like this: $array = array_map('strtolower', $array); Is there a simple way to accomplish this in Java?

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)