RPC call from server to client

709 views
Skip to first unread message

Magnus

unread,
Oct 17, 2012, 11:31:23 AM10/17/12
to google-we...@googlegroups.com
Hello,

I realized a simple chat within my chess application:

When the user posts something, the posting is sent to the server and the chat view on the client side is updated.
But when another user posts something, the user's view is not updated automatically.

I wonder how to realize an automatic update. From the server's point of view it chould be realized like this:

Whenever *some* user sends a posting, do the following:
{
 List<User> l = getAllUsersThatAreCurrentlyLoggedIn();
 for (User u:l)
  notifyClientOfUser(u);
}

However, I do not know how and where to start and how to realize the methods used above.
How can I determine the users who need to be notified?
How can I send the notification to the users? I have access to the user's session data, but how can I make a call, where do I have to define the service methods and where does the call come out within the client?

Thanks
Magnus

Mark Donszelmann

unread,
Oct 17, 2012, 11:44:03 AM10/17/12
to google-we...@googlegroups.com, google-we...@googlegroups.com
Try atmosphere

Regards
Mark

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/DoASuAbKVnkJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Stefan Ollinger

unread,
Oct 17, 2012, 11:44:26 AM10/17/12
to google-we...@googlegroups.com
Hello Magnus,

you can use WebSockets and Comet.

http://en.wikipedia.org/wiki/Comet_%28programming%29
http://de.wikipedia.org/wiki/WebSocket

That way you can send messages from the server to the client.
So if someone sends a new chat message to the server, you can broadcast
it to the interested parties.
Also see: http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern

Atmosphere is a good implementation and has support for GWT:
https://github.com/Atmosphere/atmosphere/wiki/Getting-started-with-GWT

Regards,
Stefan

Magnus

unread,
Oct 17, 2012, 1:19:09 PM10/17/12
to google-we...@googlegroups.com
Hello,

thank you for the responses and the links.

It would bother me a little bit to use a third-party library for this. If there is no other way I would do this, but at the moment I would like to know if this is really needed.

Calling the server from the client is also possible without other products. Can't I just do this in the other direction?

Define a Service/ServiceAsync/ServiceImpl and so on?

Magnus

Stefan Ollinger

unread,
Oct 17, 2012, 2:18:07 PM10/17/12
to google-we...@googlegroups.com
See answers inline.

Am 17.10.2012 15:19, schrieb Magnus:
> Hello,
>
> thank you for the responses and the links.
>
> It would bother me a little bit to use a third-party library for this.
> If there is no other way I would do this, but at the moment I would
> like to know if this is really needed.
You usually want to use a third party library for this.
>
> Calling the server from the client is also possible without other
> products. Can't I just do this in the other direction?
>
> Define a Service/ServiceAsync/ServiceImpl and so on?
You need to think about how HTTP works. The client always starts a request.
Here is an overview of push technologies:
http://en.wikipedia.org/wiki/Push_technology
>
> Magnus
> --
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/kUrlZG4kZsIJ.

Jens

unread,
Oct 17, 2012, 2:22:43 PM10/17/12
to google-we...@googlegroups.com
You can use a push approach where the server actively pushes data to its clients via WebSockets (works only on modern browsers and you need a server that knows WebSockets) or you can use a long polling approach (Comet) where the client makes a request to the server and the server does not respond immediately. The server holds the connection until data is available (in your case a new chat message in a blocking queue). As soon as the client receives a response or a connection timeout occurs the client opens a new connection to the server and again waits for server data. Long polling works in every browser and its not hard to implement. 

Downside of long polling requests are:
- There is always one active connection per user/chatter to the server to mimic server push via long polling. Some browsers only allow 2 connections to the same domain, so you would only have one additional connection for other/parallel server requests.
- It does not scale that well on server side unless you use Servlet 3.0 and its async servlets. Without async servlets each connection is handled by a thread of your servers thread pool => 1000 chatter = 1000 active connections all waiting for data = 1000 active threads. Async servlets reduce the amount of needed threads drastically.

-- J.

Magnus

unread,
Oct 17, 2012, 2:26:09 PM10/17/12
to google-we...@googlegroups.com
Hi Stefan,

I understand that HTTP cannot do what I want. But I expected that GWT provides a method for this. Obviously it does not.

Magnus

Magnus

unread,
Oct 17, 2012, 3:41:11 PM10/17/12
to google-we...@googlegroups.com
Hi Jens,

scalability is important for me. I want to make strong use of server push once I have a working skeleton. For example, I would like to push chess moves to all clients that are currently watching a chess board: The two players and all visitors. There are other chess servers that do this (e. g. www.schacharena.de), and they have thousands of users. It would be hard to believe that they use a technique with one open/waiting request per client. (BTW: Can one determine which technique is used there from the outside?)

I also read that there is "streaming" beside "long pull", but with even more drawbacks...

To get an idea how it works I would like to play around with something real. I found this:

But the implementations are web servers (Jetty, Glassfish, ...). This is much too much. I thought of a small library which provides just the server push functionality and not much more.

How can I find a real start?

Magnus

Jens

unread,
Oct 17, 2012, 5:18:02 PM10/17/12
to google-we...@googlegroups.com


scalability is important for me. I want to make strong use of server push once I have a working skeleton. For example, I would like to push chess moves to all clients that are currently watching a chess board: The two players and all visitors. There are other chess servers that do this (e. g. www.schacharena.de), and they have thousands of users. It would be hard to believe that they use a technique with one open/waiting request per client. (BTW: Can one determine which technique is used there from the outside?)

You can use Chrome Developer Tools and let it display the server requests. Looks like they load a .php page in an iframe that reload itself every 5 seconds. If the opponent has done a move the .php page contains some JS code to update the chessboard. If you dont need nearly real-time feedback from your server thats the easiest solution. In GWT terms this would be a Timer that calls your service every x seconds.


-- J.


Magnus

unread,
Oct 18, 2012, 4:56:19 PM10/18/12
to google-we...@googlegroups.com
Hi,

I took a look at most of the libraries, but there is no one that can make my happy, because none of them seems to be "lightweight".

Atmosphere requires Maven. If I go to Maven someday, I would like to do this on the basis of a free decision, but not as a dependency for the library I am looking for.
All the systems mentioned in the context of Comet (http://cometdaily.com/maturity.html) seem to be big frameworks, with much more functionality than that I am looking for. This also holds for Errai.

I am always careful with such decisions. If I always add a complete framework whenever I need a little bit of functionality, my project will explode very soon.

What seems to be nice and small and "light" is the HTML5 support for WebSockets, at least as described here (*):

One Servlet declaration, one Handler at the server and one handler at the client. This seems very attractive to me!

However, it seems that GWT supports HTML5 but without WebSockets:

Is this correct? Why does GWT support HTML5 but not for such an important thing like WebSockets?

So if I wanted to use the library above (*):
How are these projects below code.google.com organized? Is it always a jar file that one has to put into WEB-INF/lib to use the library?

I really hope that I can use this lightweight library (*) very soon and I appreciate any help that gets me started.

Magnus

Andrea Boscolo

unread,
Oct 18, 2012, 7:33:53 PM10/18/12
to google-we...@googlegroups.com
The problem is that websocket (as any other HTML5 spec) has chages a bit in the last two years making some useful libraries outdated and not definitely working.


On Thursday, October 18, 2012 6:56:19 PM UTC+2, Magnus wrote:
Hi,

I took a look at most of the libraries, but there is no one that can make my happy, because none of them seems to be "lightweight".

Atmosphere requires Maven. If I go to Maven someday, I would like to do this on the basis of a free decision, but not as a dependency for the library I am looking for.
You can always download the jars somewhere and/or use a dependency manager like Apache Ivy (that can be easily integrated with ant) that fetches Maven dependencies and/or build the jar from scratch. Maven is not an obstacle.
All the systems mentioned in the context of Comet (http://cometdaily.com/maturity.html) seem to be big frameworks, with much more functionality than that I am looking for. This also holds for Errai.
That article is quite outdated (2009), I suspect there *a lot* more frameworks out there that can make the difference. But if you want to go with websockets as lightweight as possible, both your server and your client (browser) need to support it in the most up-to-date way.

I am always careful with such decisions. If I always add a complete framework whenever I need a little bit of functionality, my project will explode very soon.

What seems to be nice and small and "light" is the HTML5 support for WebSockets, at least as described here (*):

One Servlet declaration, one Handler at the server and one handler at the client. This seems very attractive to me!
Last update is  Nov 2010, I guess the websocket specs have changed since then, so I don't think this will ever work. But you can try!

However, it seems that GWT supports HTML5 but without WebSockets:

Is this correct? Why does GWT support HTML5 but not for such an important thing like WebSockets?
Not in GWT, but you can try the GWT Elemental library (for the client) that support all HTML5 specs, just pay attention to the supported browsers.

So if I wanted to use the library above (*):
How are these projects below code.google.com organized? Is it always a jar file that one has to put into WEB-INF/lib to use the library?
You can clone a repository and build from sources or download the jar and place it in the lib folder.

I really hope that I can use this lightweight library (*) very soon and I appreciate any help that gets me started.

Magnus
 There is also another library (streaming/long polling tough) I've used some time ago http://code.google.com/p/gwteventservice/ . It adheres somehow to the server-event specifications (that is another way to say server->client communication).

Anyway I'd give atmosphere a try.

Magnus

unread,
Oct 19, 2012, 4:47:01 PM10/19/12
to google-we...@googlegroups.com
Hi Andrea!


Am Donnerstag, 18. Oktober 2012 21:33:53 UTC+2 schrieb Andrea Boscolo:

Anyway I'd give atmosphere a try.

Ok, but where can I get the right jar file? 

Just googeling around and choosing "some" jar, e. g. this one?

How do I know if it's the latest, the rignt one? (I've seen somewhere that there are different atmosphere modules/jars for different comet techniques...)

Magnus

Magnus

unread,
Oct 19, 2012, 5:12:32 PM10/19/12
to google-we...@googlegroups.com
Hello,

I found some jar somewhere, but I don't know if it's ok. I found that there are many different aptmosphere jars. There is even a special "GWT" version:

This is hard to understand for me: Why a special GWT version?
There also seem to be different atmosphere APIs...

Then, all the examples on the atmosphere homepage include only one java file. I expected atmosphere code to be on both the client and server side.

However, I still need some help to pick the richt jar/api, and I need a minimal example...

Magnus

Jens

unread,
Oct 19, 2012, 5:25:09 PM10/19/12
to google-we...@googlegroups.com
Message has been deleted
Message has been deleted

Magnus

unread,
Oct 20, 2012, 11:15:07 PM10/20/12
to google-we...@googlegroups.com
Hi,

I arrived at the following state by trial and error:

included jars:
atmosphere-gwt-client-1.0.2.jar
atmosphere-gwt-common-1.0.2.jar
atmosphere-gwt-server-1.0.2.jar
atmosphere-runtime-1.0.2.jar

example project:

I just fetched the files from the example and put them into a new GWT project, because I do not use Maven.
Especially, I did not define any servlets.

When starting the app I get the runtime error attached below.

The code tries to access "testatmosphere/gwtComet/room1", so I thought there should be a servlet. I defined ChatHandler to be a servlet, but this also did not work, because ChatHandler is not derived of the servlet class.

I think I am close to a working example now, but I need the final hint from you! :-)

Magnus




Sun Oct 21 01:10:58 CEST 2012 org.atmosphere.gwt.client.AtmosphereClient INFO: Created transport: org.atmosphere.gwt.client.impl.WebSocketCometTransport
Sun Oct 21 01:10:58 CEST 2012 org.atmosphere.gwt.client.AtmosphereClient INFO: Server does not support WebSockets
Sun Oct 21 01:10:58 CEST 2012 test.client.GWTDemo SEVERE: comet.error [connected=false] (404)
com.google.gwt.user.client.rpc.StatusCodeException: 404 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> <title>Error 404 NOT_FOUND</title> </head> <body><h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre> <p>RequestURI=/testatmosphere/gwtComet/room1</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> </body> </html> 
   at org.atmosphere.gwt.client.impl.StreamingProtocolTransport.onReceiving(StreamingProtocolTransport.java:50)
   at org.atmosphere.gwt.client.impl.HTTPRequestCometTransport.onLoaded(HTTPRequestCometTransport.java:204)
   at org.atmosphere.gwt.client.impl.HTTPRequestCometTransport.access$3(HTTPRequestCometTransport.java:201)
   at org.atmosphere.gwt.client.impl.HTTPRequestCometTransport$3.onReadyStateChange(HTTPRequestCometTransport.java:131)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
   at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
   at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
   at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
   at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
   at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
   at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
   at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
   at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
   at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
   at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
   at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
   at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
   at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
   at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
   at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
   at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
   at java.lang.Thread.run(Thread.java:636)

Magnus

unread,
Oct 25, 2012, 1:25:54 PM10/25/12
to google-we...@googlegroups.com
Hello,

could please someone point me to the right direction?

I believe I have all jars now and a complete example. But it does not work yet.

Maybe I have to declare a servlet or something like this?
(I did not use any poms, just created an empty GWT project and added the jars + example code.)

Magnus

Jens

unread,
Oct 25, 2012, 2:13:42 PM10/25/12
to google-we...@googlegroups.com
I would check the example's xml files in WEB-INF and META-INF directory to see if any servlet paths are incorrect for your deployment. Maybe you have just deployed it differently than the example expects (different webapp context root for example).

Also, just to test the example, can't you simply install maven on your machine and use "mvn gwt:run" inside the example directory where the pom.xml is?

-- J.

Michael Hirsch

unread,
Oct 26, 2012, 3:54:35 AM10/26/12
to google-we...@googlegroups.com


On Oct 18, 2012 10:56 AM, "Magnus" <alpine...@googlemail.com> wrote:
>
> Hi,
>
> I took a look at most of the libraries, but there is no one that can make my happy, because none of them seems to be "lightweight".
>
> Atmosphere requires Maven. If I go to Maven someday, I would like to do this on the basis of a free decision, but not as a dependency for the library I am looking for.
> All the systems mentioned in the context of Comet (http://cometdaily.com/maturity.html) seem to be big frameworks, with much more functionality than that I am looking for. This also holds for Errai.

Errai does provide a lot of functionality, but they have tried to make it possible to include  only  what you want.  You should be able to use only the parts that implement the errai bus.

Using the errai bus would make it easy to implement a solution.    Errai makes it trivially  easy to send messages.  And it knows to use web sockets,  if they are supported.

--Michael

Mike Dee

unread,
Oct 26, 2012, 6:12:03 PM10/26/12
to google-we...@googlegroups.com
I wonder how this is done in Google Docs? The approach may be a bit of overkill for a chat client though. Multiple users can edit a word processing document or spreadsheet simultaneously.

I've seen talks about how this is done conceptually.  It involved the command pattern and there was a way to ship (serialized) objects from server to client.  I think it used the Google Chat protocol.

Thomas Broyer

unread,
Oct 26, 2012, 6:21:23 PM10/26/12
to google-we...@googlegroups.com


On Friday, October 26, 2012 8:12:03 PM UTC+2, Mike Dee wrote:
I wonder how this is done in Google Docs? The approach may be a bit of overkill for a chat client though. Multiple users can edit a word processing document or spreadsheet simultaneously.

I've seen talks about how this is done conceptually.  It involved the command pattern and there was a way to ship (serialized) objects from server to client.  I think it used the Google Chat protocol.


Docs being done in Closure, it's probably using BrowserChannel. If you run on AppEngine, you can use the Channel API. Otherwise, use WebSockets or anything Comet-like (long-polling).

Sebastian Rothbucher

unread,
Nov 3, 2012, 10:48:46 AM11/3/12
to google-we...@googlegroups.com
by far and large, you'd have to poll (asynchronously)
Reply all
Reply to author
Forward
0 new messages