November 2017
Intermediate to advanced
398 pages
10h 14m
English
WebSocket API is another addition to the java.httpclient package. As explained earlier, it enables having full duplex communication between the client and the server. This package provides various methods to help build messages, listen for events and messages, and handle partial messages. This is one of the important additions to the Java network API as it can process client’s requests seamlessly. Let’s take the following example:
public class MyFirstWebSocketListener implements WebSocket.Listner{ @Override public CompletionStage<?> onText(WebSocket webSocket, CharSequence message, WebSocket.MessagePart part){ //Process the message here } }
The client can then use the following code to call this:
URI processAllURI = ...
Read now
Unlock full access