public class WebSocketClient extends WebSocket
Original implementation based on "HyBi Working Group, draft-ietf-hybi-thewebsocketprotocol-07, April 22, 2011, by I. Fette, Google Inc." — updated to RFC 6455 in March 2026.
See https://tools.ietf.org/html/rfc6455 for more information.
The WebSocket protocol enables two-way communication between a user agent running untrusted code running in a controlled environment to a remote host that has opted-in to communications from that code. The security model used for this is the Origin-based security model commonly used by Web browsers. The protocol consists of an initial handshake followed by basic message framing, layered over TCP. The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections (e.g. using XMLHttpRequest or <iframe>s and long polling).
WebSocket.StateACCEPT_GUID, CLOSE_GOING_AWAY, CLOSE_NORMAL, CLOSE_PROTOCOL_ERROR, CRLF, input, isSecure, output, protocolVersion, ssubProtocol, state| Constructor and Description |
|---|
WebSocketClient(Socket socket,
boolean isSecure,
String host,
int port,
String resource,
List<String> subProtocols)
Establishes the WebSocket connection using an already connected
socket.
|
WebSocketClient(Socket socket,
InputStream input,
OutputStream output,
boolean isSecure,
String host,
int port,
String resource,
List<String> subProtocols)
Establishes the WebSocket connection using an already connected
socket.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isServerSide()
This is the client side of the WebSocket connection.
|
void |
performHandshake(boolean doFailForUnsupportedSubProtocol)
Performs the WebSocket handshake per RFC 6455 Section 4.
|
close, closeSocket, closeSocketHard, getBinaryMessage, getOldTextProtocol, getProtocolVersion, getServerSubProtocol, getState, getTextMessage, hasBinaryMessage, hasTextMessage, isVerbose, log, log, readMessage, sendBinaryData, sendBinaryData, sendCloseFrame, sendText, setOldTextProtocol, setProtocolVersion, setVerbosepublic WebSocketClient(Socket socket, boolean isSecure, String host, int port, String resource, List<String> subProtocols) throws IOException
socket - The established socket.isSecure - If the connection is secure.host - The host used to establish the socket connection.port - The port used to establish the socket connection.resource - The URI.subProtocols - The list of sub-protocols requested, null for none.IOException - For failures.public WebSocketClient(Socket socket, InputStream input, OutputStream output, boolean isSecure, String host, int port, String resource, List<String> subProtocols) throws IOException
socket - The established socket.input - The input stream.output - The output stream.isSecure - If the connection is secure.host - The host used to establish the socket connection.port - The port used to establish the socket connection.resource - The URI.subProtocols - The list of sub-protocols requested, null for none.IOException - For failures.protected boolean isServerSide()
isServerSide in class WebSocketpublic void performHandshake(boolean doFailForUnsupportedSubProtocol)
throws IOException
The handshake consists of an HTTP Upgrade request with a Sec-WebSocket-Key header containing a random 16-byte nonce (Base64-encoded). The server responds with a Sec-WebSocket-Accept header containing SHA-1(key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11") in Base64.
doFailForUnsupportedSubProtocol - Flag indicating a WebSocketException is thrown if the
server doesn't support requested protocols (if any).IOException - For failures.EOFException - For unexpected closure of the socket.WebSocketException - For exceptions relating to Web Sockets (protocol, etc).Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.