WebSocket Sample

These WebSocket samples show how to set up WebSocket Endpoints using annotations or programmatically. These samples exercise opening, reading from, writing to, and closing a WebSocket connection. Also shown is the use of encoders, decoders, the PathParam annotation, and Pong message processing.

This sample can be installed onto runtime versions 8.5.5.4 and later.

Installation Instructions

Online installation (requires 8.5.5.6 or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install WebsocketSample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the WebsocketSample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar WebsocketSample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

To run the WebsocketApp application:

  1. Start the WebsocketSample server by running the command below from the bin directory in the Liberty profile installation:
    server run WebsocketSample
  2. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application WebsocketApp started in XX.XX seconds.
  3. In your browser, enter the URL for the application: http://localhost:9136/WebsocketApp/index.html (where port 9136 assumes the httpEndpoint provided in the sample server.xml has not been modified).
     
  4. In your browser choose a link and following the instructions to exercise a WebSocket sample.

Notes

The WebsocketApp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

The application is automatically installed because it is located in the server dropins directory. Any number of applications can be installed from this location.

Sample Structure

  • wlp
    • usr
      • servers
        • WebsocketSample
          • Copyright.txt
          • dropins
            • WebsocketApp.war
          • readme.html
          • server.xml