Errai: The browser as a platform

Monday, February 20, 2012

WebSockets with Errai

Another new feature in Errai 2.0 is the addition of WebSockets support for the ErraiBus. It provides a transparent COMET-to-WebSockets session upgrade mechanism within the bus itself. This means, that no changes are required to your existing Errai code to take advantage of WebSockets. When enabled, all bus traffic (CDI events, RPC, Bus Messages) will all be routed over the WebSocket channel.

WebSocket support is still not very up-to-snuff in the world of Java Servlet containers and even web browsers. Therefore, our existing WebSocket support is technically considered experimental.

But when it comes to the open source community, there's never any shortage of people willing to play. And we'd love it for you to give the feature a spin.

The WebSocket server is a built-in feature of ErraiBus 2.0. Therefore all you really need to do, metaphorically speaking, is flip the switch to turn it on. You do this by adding the following line to your ErraiService.properties file:

errai.bus.enable_web_socket_server=true

Now startup your app, and use a compatible browser (like Chrome or Firefox) and connect to your app. Then, open up your JavaScript console and check to see that it actually worked:



Hey, check it out! Errai opened a web socket. You can actually see more information about the connection state itself by executing the JavaScript function errai_status() from the console:



You may notice something curious here, however: the WebSocket server is running on port 8085 not port 8080 with the rest of the appserver. This is simply because currently, due to lack of standardized support in Java Servlet containers (although there is an effort afoot to remedy this), we currently run the WebSocket server as a sideband server.

This, of course, is not ideal and it's something that we at JBoss are working to address in an internal cross-project effort. I hope to be making some interesting announcements about that over the next year.

But that's not the end of the world, of course. There are front-end proxy solutions which can be used to remedy this problem and munge the servicing of the WebSocket onto the same public-facing port -- the facilities of which are usually good practice for any application server environment in any case.

Anyways, I'd love to hear back from the community on this.

Mike, out.

5 comments:

  1. Wow ! This is awesome !

    Though currently the server must be behind an apache, nginx, HA-Proxy, or Varnish... but the functionality and ease of use is great!

    Excellent work, Mike!

    ReplyDelete
  2. I'm very happy being Herpes free now. It was a sad incident that was announced to me after the check up in the hospital and I was diagnosed of HSV 2. I thank God now for using Dr.odey Abang to cure my virus. I'm not ashamed to say this because no virus of such can be detected in me. I'm Charlotte from Columbia. I thought about it many Times when I heard about this Herbal cures for Herpes. I was really happy when I came across blogs of comments of Doctors who run cures sicknesses and was comfortable to try Dr. Abang from patients testimony I came across here on my online page. I knew now they are real Africa herbalists who run cures for Herpes. There's every opportunity to be cure with natural herbs, because all medical prescriptions are derived from herbs and roots. Its really hard time living with Herpes on drugs which can't get you cure. I tried this and I can boost of myself now as a woman. I need to be loved not to lost, get your instant cure to all sicknesses from Dr, Odey Abang.
    He cures HSV,HPV,Cancer,low spam count and much more from the evidence I saw 💯 % sure no site effects with active immune booster

    Email him for you cure
    Odeyabangherbalhome@gmail.com
    WhatsApp/calls
    +2349015049094

    ReplyDelete