Migrate WebSocket and ByteSocket Applications to Kaazing WebSocket Gateway 4.0
This topic covers the issues involved in migrating Kaazing WebSocket Gateway 3.2-3.5 Java clients built using the ByteSocket API to the Java API in Kaazing WebSocket Gateway 4.0. Kaazing WebSocket Gateway 4.0 no longer includes the ByteSocket API because the WebSocket and WsURLConnection classes in the Kaazing WebSocket Gateway 4.0 Java library support binary messaging.
For more information about the Kaazing WebSocket Gateway 4.0 Java API, see Interact with Kaazing WebSocket Gateway Using the WebSocket API and Java Client API.
Before You Begin
This procedure is part of Checklist: Build Java Clients Using Kaazing WebSocket Gateway:
- Set Up Your Development Environment
- Interact with Kaazing WebSocket Gateway Using the WebSocket API
- Interact with Kaazing WebSocket Gateway Using the EventSource API
- Migrate WebSocket and ByteSocket Applications to Kaazing WebSocket Gateway 4.0
- Secure Your Java and Android Clients
- Display Logs for the Java Client
- Troubleshoot Your Java Client
Note: Learn about supported browsers, operating systems, and platform versions in the Release Notes.
Legacy Client Support
Kaazing WebSocket Gateway 4.0 supports Java clients written using the Kaazing WebSocket Gateway 3.2-3.5 Java APIs. You do not need to migrate your legacy Java client to use Kaazing WebSocket Gateway 4.0. If you wish to take advantage of the new Java API for Kaazing WebSocket Gateway 4.0 or new features of Kaazing WebSocket Gateway 4.0, you must migrate your Java client.
The new Java API for Kaazing WebSocket Gateway 4.0 is easier to use than previous versions, but it does require that you change your Kaazing WebSocket Gateway 3.2-3.5 Java API client code to take advantage of it.
Binary Support in the Kaazing WebSocket Gateway 4.x Java API
Both WebSocket and WsURLConnection classes support APIs that enable use the use of byte-based data streams as they define java.io.InputStream and java.io.OutoutStream methods. getInputStream() is used for receiving binary streams and getOutputStream() is used to sending binary streams. If either method is used to receive text messages, or the methods are invoked before a connection is made, then an IOException is thrown. Once the connection is closed, a new InputStream or OutputStream should be obtained using these methods after the connection has been established. Using the old InputStream or OutputStream will result in IOException.
For information and example, see Interact with Kaazing WebSocket Gateway Using the WebSocket API.
Blocking Calls and ByteSocketListener
The ByteSocketListener interface in the Kaazing WebSocket Gateway - HTML5 Edition 3.x Java WebSocket API is not included in the Java WebSocket API for Kaazing WebSocket Gateway 4.0.
WebSocket.ReadyState and ByteSocket.ReadyState No Longer Used in the Java WebSocket API
The WebSocket.ReadyState class in the Java WebSocket API in Kaazing WebSocket Gateway - HTML5 Edition 3.x is not included in the Java WebSocket API for Kaazing WebSocket Gateway 4.x (all editions).
The Java WebSocket API for Kaazing WebSocket Gateway 4.x supports blocking for the connect() and close() methods and eliminates the need for the WebSocket.ReadyState and ByteSocket.ReadyState.
Similarly, the InputStream, Reader, and WebSocketMessageReader support blocking calls that eliminate the need for MessageEvent as the control will come out of the blocking call only when the message has arrived.