We’ve just released the latest GA version of WebSphere Application Server Liberty profile (8.5.5.4), which contains some new features, including WebSockets support. So I thought it would be a good time to share my WebSocket planning poker application with you as an example of creating a simple real-time communication web app built on WebSockets.

It’s no secret that I’m a bit of a WebSockets fanboy. One of my first jobs in IBM as a developer was doing JavaScript development. We had a webpage polling a server endpoint for updates as there was no easy way to have full duplex communication between clients and servers; to update the content of a page from the server you have to keep asking the server if anything’s changed, which really didn’t feel right.

WebSockets solves that problem in a much more efficient way. You can hear more about WebSockets as a technology solution on our podcast:

Anyway enough about WebSockets – you came here to read about the new WebSocket sample application!

The idea for this application is from my time on the Liberty development team when we were doing planning poker. The application we were using was OK but didn’t do everything I wanted it to do, so I decided to write my own. At the same time we were implementing WebSockets which looked to solve many of the technical hurdles I needed to solve when creating a webpage with real time chat support. The sample isn’t pretty – but it is functional:


planningPoker

The following YouTube video quickly walks through how the application works and how to deploy it. It highlights how easy WebSockets make full duplex communication between client and server.

The application code is available on our GitHub repository here: https://github.com/WASdev/sample.planningpoker – you can download the code to Eclipse and deploy it to a Liberty server straight away (just remember to add the websocket-1.0 and the servlet-3.1 features in your server xml, and make sure you have either the latest beta or the latest GA version (8.5.5.4) of Liberty).

If you have any questions around WebSockets and how to use them in the Liberty profile please feel free to ask on Stack Overflow.

20 comments on"WebSocket sample application"

  1. Hi,I want to connect to websocket server by was://
    (Secure connection ) by cant,connection failed happened,I activated SSL feature,and I can get rest request on https,but can not get websocket services,in log file of liberty not anything logged,can you help me?

    • Hi Hamid,

      Just to confirm that you’re using wss:// and not was:// as the prefix for the websocket connection? (was:// is not a protocol – wss:// is for secure websockets).

      Thanks,
      Tom

  2. (index):8 WebSocket connection to ‘ws://litianwei-pc:9080/PlanningPoker/PokerEndpoint’ failed: Error during WebSocket handshake: Unexpected response code: 404

    • Can you check that you have the websocket feature enabled in the server.xml? It’s claiming the websocket isn’t there but the server must be up as it is sending you the webpage which is trying to connect to the websocket.

      • How to enable server.xml functionality in the profile of websocket

        • In your server.xml make sure that you have the following line in the featureManager’s list of features:

          <feature>websocket-1.1</feature>

  3. Is there a recommended Java client that works with Liberty’s WebSockets? I’m trying Tyrus which worked a little bit to start but now I’m seeing nio and ssl errors.

  4. […] Liberty profile 8.5.5.4 you can use web sockets in your Java applications. This allows sending events from the server to […]

  5. Hi Tom,

    Thanks for that walkthrough!

    Can some configurations in web.xml, instead of server.xml , be used for enabling websocket in a web application?

    Or to put it straight, can a non-Liberty profile be configured for WebSockets?

    Thanks,
    Joseph

Join The Discussion

Your email address will not be published. Required fields are marked *