WebSockets Support for Java

WebSockets Support for Java

WebSockets provide a single full-duplex TCP connection between a client and server. Messages can be transmitted instantly in both directions with little overhead while using standard HTTP ports and common proxy infrastructure.

The platform supports WebSockets through the Shared Load Balancer, NGINX load balancer, and all available Java application servers. Most Java servers require only application-level implementation; GlassFish additionally requires server-side activation.

Common Java Servers Implement WebSockets inside the application without special server configuration.
GlassFish Enable the WebSockets Support option in the GlassFish Administration Console.

Create a Java Environment

1Open the environment wizard

Sign in to the platform dashboard and click New environment.

New environment button
Start creating a Java environment from the dashboard.

2Select GlassFish

Open the Java tab, select GlassFish, define the vertical scaling limits with the Cloudlet sliders, enter an environment name such as java-websockets, and click Create.

GlassFish environment topology
Create the GlassFish environment and configure its Cloudlet limits.

Wait until the environment is created and the GlassFish node reaches the running state.

GlassFish environment created
The new Java environment appears in the dashboard.

Deploy the WebSocket Application

Deploy the Java application that requires WebSocket support to the GlassFish environment.

  • Upload a local application archive.
  • Deploy the application from a remote URL.
  • For a remote VCS repository, add a Maven build node and use the Java VCS deployment workflow.

After deployment, the application is listed in the environment’s deployed-project column.

Java WebSocket application deployed
The WebSocket application has been deployed to GlassFish.

Open the GlassFish Admin Console

1Open the Admin Panel

Click the GlassFish Additionally button and select Admin panel > Login. The console can also be opened through the direct link sent by email after environment creation.

GlassFish Admin Panel option
Open the GlassFish Administration Console from the dashboard.

2Sign in

Enter the GlassFish administration credentials provided in the environment-creation email and click Login.

GlassFish Administration Console login
Use the emailed GlassFish administrator credentials.

Enable WebSockets Support

1Open the HTTP listener settings

In the GlassFish Administration Console, navigate to:

Configurations > gfcluster-config > Network Config > Protocols > http-listener-1

2Enable WebSockets

Open the HTTP tab, select the WebSockets Support checkbox at the bottom of the page, and click Save.

Enable WebSockets Support in GlassFish
Enable the WebSockets Support option for http-listener-1.
Save the setting: The checkbox change is not applied until the HTTP listener configuration is saved.

Restart and Test GlassFish

1Restart GlassFish

Return to the platform dashboard and restart the GlassFish node to apply the WebSocket configuration.

Restart GlassFish node
Restart GlassFish after enabling WebSockets Support.

After GlassFish returns to the running state, open the deployed application in a browser and verify that its WebSocket functionality works correctly.

All other platform-provided Java application servers generally support WebSockets through application-level implementation without the additional GlassFish administration step.

What’s next?