WSO2 AS 5.3.0 supports WebSocket 1.1 API as defined by the JSR-356 specification. This is provided by Apache Tomcat, which is embedded in AS. You can run the following sample web application to see how WebSockets work in AS.
Note that you do not need additional configurations on AS server-level to enable Websocket support for web applications.
Running the sample
The "Example" sample is deployed in AS by default. You can run this sample as explained below.
Start WSO2 Application Server.
Log in to the management console and click List under Applications to open the Running Applications page.
The "example" sample will be listed as a web application. Click Go to URL to open the web application. Alternatively, you can directly point your browser to the URL of this sample, which is http://localhost:9763/example/. Note that the port number in the URL needs to be updated if you have set a port offset for the server in the
When you open the URL, click Websocket examples. The following samples will be listed:
Echo example: This sample echoes whatever the message you send to the server via websocket. There are several websocket endpoints listed here to illustrate three different mechanisms that implement websocket services.
programmatic API - Invoking a Websocket endpoint that is registered programmatically. This is the interface-driven approach where the developer implements the
javax.websocket.Endpointinterface to create the service.
annotation API (basic) - Invoking a websocket service that is defined using java annotations. This is the annotation-driven approach where the developer interacts with the websocket lifecycle events via annotated POJOs.
annotation API (stream) - This also follows the annotation-driven approach, and the messages sent from the server are streamed.
- Chat example: This simulates a standard chat application. In this application, the messages received are broadcast to all the users that are connected to this websocket service.
- Multiplayer snake example
- Multiplayer drawboard example