WebSockets represent a long awaited evolution in client/server web technology. They allow a long-held single TCP socket connection to be established between the client and server which allows for bi-directional, full duplex, messages to be instantly distributed with little overhead resulting in a very low latency connection.
You can achieve the following benefits using WebSockets :
- Reduce unnecessary network traffic and latency using full-duplex through a single connection.
- Streaming through proxies and firewalls, supporting simultaneously upstream and downstream communication.
- Backward compatible with the pre-WebSocket world by switching from an HTTP connection to WebSockets.
So WebSockets can make your applications faster, more efficient, and more scalable.
Let's deploy small application, which uses WebSockets and you'll see how easy it is.
- Create an environment
- Log into the Jelastic Manager
- Click Create environment to set up a new environment in Jelastic.
- In the Expert environment topology window, select GlassFish as your application server and switch on Public IPv4 for it. Pick Maven as your build node and type your environment name, for example, web-socket-test. Then click Create.
- In a minute your environment with both GlassFish and Maven will be created and appears in the environments list.
- Build and deploy a project
- Click on Add project button for Maven.
- In the dialog, navigate to Git tab (or SVN tab). Specify your project name, Path to your project, Branch, Login and Password of your repository, the name of your Environment, Context in which you will deploy your project, and click Add. We use simple chat application as an example. You can find this project here.
Now your project is successfully added.
- Click on Build and deploy button for your project.
- Configure GlassFish
- Go to GlassFish admin panel and log in with credentials, which Jelastic sent you, when you created the environment.
- Navigate to Configurations -> gfcluster-config -> Network Config -> Protocols -> http-listener-1, select HTTP tab and enable Websockets Support. Don't forget to save the changes!
- Restart GlassFish.
- Start an application
This process can take several minutes. Your project will appear in the context that you have specified and you will see a war file in the Deployment Manager.
Open your application in a web browser and ensure that it works fine.