GWT Websockets with Elemental

1.6k views Asked by At

I would like to use websockets technology in a GWT web application.

I know that there are some implementations using Commet and Atmospere, but i would like to avoid them as they are actually a long lived HTTP request to the server.

I have my own implementation of web sockets and i would like to know if someone knows a client side library or way that i can achieve to communicate between my client/server with websockets. More specifically, i heard that GWT Elemental package provides this kind of functionality. I researched (googled) about that but couldn't find anything specific.

Could someone point me to the right direction? Any suggestions except GWT Elemental are welcomed as well.

EDIT: I found out the below link, which is GWT-Elemental interface. I can see that it is a ReleaseCandidate version, but i would be willing to try using the functionality. So if anyone has used that before i would like to know his/her comments/suggestions.

http://grepcode.com/file/repo1.maven.org/maven2/com.google.gwt/gwt-elemental/2.5.1-rc1/elemental/html/WebSocket.java?av=f

1

There are 1 answers

0
Ümit On

Well I haven't used Websockets from Elemental but the FileReader API and it worked fine.
However you have to take into account that Elemental is highly experimental. Some of the specifications in the IDL of Webkit have changed since the Elemental library was auto-generated and thus won't work.
So you might need to find workarounds, etc.

Working with Elemental is quite straightforward. You usually use Browser or Window from the package to get an instance of the class you want to work with. Something like this:

Window window = Browser.getWindow();
WebSocket webSocket =  window.newWebSocket(URL);
webSocket.setOnmessage(new EventListener() ....);
websocket.send();