Tuesday, January 21, 2014

Re: How to build system to check the incoming messages in GWT?

Hi,

I don't think there is a universal solution to this it comes down to
the capabilities of the browsers that are connecting to the site and
how you want to trade off timeliness versus server cost. In terms of
pushing to the client I would tend to use one of four techniques.

* Polling: Check every time period N.
* Long Polling: Start poll but suspend the request and have server
respond when needed.
* SSE (aka Server Sent Events): Client opens connection and server
sends events to message as needed (also handles automagic
reconnection, and routing messages on client-side)
* WebSockets: Client opens connection to server, bi-directional communication.

It seems like what you probable want is SSE if available in the
browser and then fall back to polling strategy. In terms of what it
looks like in GWT you can check out the gwt-eventsource [1] library.
See [2] for some example code for the client and server (using jersey
jaxrs). If you want to use web sockets you can check out the
gwt-websockets [3] library and corresponding example code at [4].

Holler if you have any problems. Just note that I was working on
gwt-eventsource this morning and only just released it to Maven
Central an hour ago so you may need to wait a couple some time before
the main repository has synchronized the release.

[1] https://github.com/realityforge/gwt-eventsource
[2] https://github.com/realityforge/gwt-eventsource-example/tree/master/src/main/java/org/realityforge/gwt/eventsource/example
[3] https://github.com/realityforge/gwt-websockets
[4] https://github.com/realityforge/gwt-websockets-example/tree/master/src/main/java/org/realityforge/gwt/websockets/example

On Wed, Jan 22, 2014 at 12:48 PM, Tom <HenryHa5@gmail.com> wrote:
> Ok, I got a message system, user can send message to each other at any time.
> The message icon is in the header. I want to program so that when person A
> sends a message to person B, then B can be able to see the message in the
> header immediately & automatically without needing to refresh the page.
>
> How does that system work?
>
> I think there some solutions here,
>
> -Solution1: we program so that each active page will check the message every
> 5 minutes. This is not too smart since if there's no message, the server
> still receives the call every 5 min. Imagine there is a million users & if
> each user opens the page & lives the page for the whole day then server will
> receive too many unnecessary calls.
>
> -Solution2: Do some sort of global variable that check the incoming message.
> When A sends message to B, the global variable will be changed, & we needs
> to do something so that that variable can check all the active pages that
> user B is opening & the system sends the reminder to all those pages. I am
> not sure if this is the right way to do.
>
> Can you find a better solution?
>
> Does anyone know what is the wright way to build this system?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit+unsubscribe@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Cheers,

Peter Donald

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate