Checklist: Build Java Clients Using Kaazing WebSocket Gateway
The following checklist provides the steps necessary to build clients to communicate with Kaazing WebSocket Gateway:
# | Step | Topic or Reference |
---|---|---|
1 | Learn about supported browsers, operating systems, and platform versions. | Release Notes |
2 | Learn how to use the Kaazing Java client library in your Java applet or stand-alone Java application. | Set Up Your Development Environment |
3 | Use the WebSocket API provided by the Kaazing Java client library to transmit data (both text and binary) over WebSocket. | Interact with Kaazing WebSocket Gateway Using the WebSocket API |
4 | Use the EventSource API provided by the Kaazing Java client library to take advantage of the HTML5 Server-Sent Events standard. | Interact with Kaazing WebSocket Gateway Using the EventSource API |
5 | Migrate your legacy Kaazing WebSocket Gateway WebSocket or ByteSocket-based client to the WebSocket API-compliant libraries in Kaazing WebSocket Gateway 4.x. | Migrate WebSocket and ByteSocket Applications to Kaazing WebSocket Gateway 4.x |
6 | Learn how to authenticate your Java or Android client with the Gateway. | Secure Your Java and Android Clients |
7 | Set up logging for your client. | Display Logs for the Java Client |
8 | Troubleshoot the most common issues that occurs when using Java clients. | Troubleshoot Your Java Client |
Overview of Java
Java applications are platform–independent because they are compiled to bytecode that can then be run on a Java virtual machine (JVM) on any certified operating system.
Note: A Java applet is a Java program you can include in an HTML page. Java applets run in the browser's JVM. This documentation does not cover Java applets. For more information about Java and Java applets, visit http://java.com.
WebSocket and Java
Kaazing WebSocket Gateway provides support for its HTML5 Communication protocol libraries in Java. Using the Java client library, you can enable the HTML5 Communication protocols (for example, WebSocket and Server-Sent Events (SSE)) in new or existing Java applications. For example, you can create a Java client to get streaming financial data from a back-end server using WebSocket, or you can create a Java client to receive streaming news data through SSE. The following figure shows a high-level overview of the architecture:

Taking a Look at the Java Client Demo
Before you start, take a look at an out of the box demo built using the Java client library: the Java applet that is part of the Kaazing WebSocket Gateway bundle. To see this Java applet in action, perform the following steps:
- Start the Gateway as described in Setting Up Kaazing WebSocket Gateway.
- In a browser, navigate to the out of the box demos at http://localhost:8001/demo/.
- Click Java and follow the instructions.
The out of the box Java demo shows WebSocket being used in a Java environment.
Taking a Look at the Java Client Demo Using Eclipse
Running the out of the box Java demo in Eclipse enables you to see the code and a working Java client. The Kaazing WebSocket Gateway download (the full download, not the “base” download) includes the demo files, and these can be easily added to an Eclipse project using the following steps (for download information, see What are my download options? in Setting Up Kaazing WebSocket Gateway):
- Open Eclipse. If you do have Eclipse, you can download it and install it.
- In Eclipse, in the File menu, click New, and then click Java Project.
- Enter a name for the project, such as WebSocket, and click Next.
- In Java Settings, click the Libraries tab, and then click Add External JARs.
- Navigate to the Kaazing WebSocket Gateway Java libraries here: GATEWAY_HOME/lib/client/java, and double-click the library com.kaazing.gateway.client.jar.
- Click Finish.
- In your new project folder in Eclipse, right-click the src folder under your new project, click New, and then click Package.
- In Java Package, enter the name com.kaazing.net.ws.demo and click Finish.
- In your system's file manager, navigate to the demo source files that are included with the Kaazing WebSocket Gateway download:
GATEWAY_HOME/demo/java/src/gateway/com/kaazing/net/ws/demo. - Copy the files named LoginDialog.java and WebSocketFrame.java.
- In Eclipse, right-click the com.kaazing.net.ws.demo package under the src folder in your new project, and click Paste. The demo source files are added to the package.
- Start the Gateway as described in How do I start and stop the Gateway? in Setting Up Kaazing WebSocket Gateway.
In Eclipse, from the Run menu, click Run As and then Java Application. (By default, Eclipse should be configured to build the project automatically. If you receive a build error, from the Project menu, click Build Project.)
The Java client launches in a new window titled WebSocket Echo Demo.
- Click Connect. The Log displays:
CONNECTED
CONNECT: ws://localhost:8001/echo - Click Send Text. The Log displays the sent text message and the Echo response from the Gateway:
RESPONSE:Hello, WebSocket!
SENT:Hello, WebSocket! - Click Send Binary. The Log displays the sent binary message in hexadecimal and the Echo response from the Gateway:
RESPONSE: 48 65 6c 6c 6f 2c 20 57 65 62 53 6f 63 6b 65 74 21
SEND BINARY: 48 65 6c 6c 6f 2c 20 57 65 62 53 6f 63 6b 65 74 21 - Click Close to close the WebSocket connection.