WebSockets Support for Java
The WebSocket protocol was created to replace older two-way communication methods that used HTTP, as HTTP wasn’t originally designed for this purpose. WebSockets set up a single, full-duplex TCP connection between the client and server, allowing instant message transmission with minimal overhead in both directions. They work over standard HTTP ports (80 and 443) and support HTTP proxies, balancing efficiency and reliability.
Our platform increases WebSocket support by integrating it with the Shared Load Balancer and NGINX balancer node, so you can use WebSockets without needing an external IP address for your server. The easiest way to set up WebSockets for your application is by placing an NGINX balancer in front of it. Detailed setup instructions are available here.
If this method doesn’t meet your needs, WebSockets are also supported by all Java application servers on our platform. Implementing WebSockets for Java usually involves configuring your application itself and doesn’t require special server settings, so your only limit is your programming skills and creativity.
The only exception is GlassFish, which requires some server-side configurations to activate WebSocket support. Follow the simple instructions below to set it up.
Create an Environment and Deploy a Project
1. Log into the platform dashboard using your username and password.
2. Click “New Environment” in the top-left corner of the dashboard.
3. Go to the Java tab in the environment setup window and choose GlassFish as your application server. Use the cloudlet sliders in the Vertical Scaling section to set the resource limits. Enter a name for your environment (e.g., java-websockets) and click “Create.”
4. After a few minutes, your environment with the GlassFish server will be created and appear on the dashboard.
5. Now you can deploy your application that requires WebSockets support to your environment. You can do this using a local archive or URL. If you prefer to use a remote VCS repository, add the Maven node to your environment setup and follow this guide.
Once deployed, your application will appear in the appropriate panel column.
Enable GlassFish WebSockets Support
The next step is to enable WebSockets support for your GlassFish application server through its Administration Console. Here’s how to do it:
1. Go to the GlassFish admin panel. You can access it via the details you receive in email.
2. In the new browser tab, enter the credentials you received in the email and click the “Login” button.
3. After logging in, go to the left-hand menu and navigate to Configurations > gfcluster-config > Network Config > Protocols > http-listener-1. Then, switch to the HTTP tab and check the box for WebSockets Support at the bottom of the page.
Remember to save your changes!
4. Go back to your dashboard and restart GlassFish to apply the changes.
Now that all the configurations are completed, open your application in a browser to ensure that it works correctly.
Enjoy!