public class WebSocketServer extends WebSocket
Original implementation based on "HyBi Working Group, draft-ietf-hybi-thewebsocketprotocol-03, October 17, 2010, 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 |
|---|
WebSocketServer(InputStream input,
OutputStream output,
boolean isSecure)
Establishes the WebSocket connection using streams only (no raw Socket
reference).
|
WebSocketServer(Socket socket,
boolean isSecure)
Establishes the WebSocket connection using an already connected
socket.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isServerSide()
This is the server side of the WebSocket connection.
|
void |
performHandshake(String resource,
Map<String,String> headerFields,
List<String> subProtocols,
boolean doFailForUnsupportedSubProtocol)
Performs the WebSocket server-side handshake per RFC 6455 Section 4.2.
|
close, closeSocket, closeSocketHard, getBinaryMessage, getOldTextProtocol, getProtocolVersion, getServerSubProtocol, getState, getTextMessage, hasBinaryMessage, hasTextMessage, isVerbose, log, log, readMessage, sendBinaryData, sendBinaryData, sendCloseFrame, sendText, setOldTextProtocol, setProtocolVersion, setVerbosepublic WebSocketServer(Socket socket, boolean isSecure) throws IOException
socket - The established socket.isSecure - If the connection is secure.IOException - For failures.public WebSocketServer(InputStream input, OutputStream output, boolean isSecure) throws IOException
input - The input stream.output - The output stream.isSecure - If the connection is secure.IOException - For failures.protected boolean isServerSide()
isServerSide in class WebSocketpublic void performHandshake(String resource, Map<String,String> headerFields, List<String> subProtocols, boolean doFailForUnsupportedSubProtocol) throws IOException
The HTTP request has already been read and parsed by the caller (e.g. HttpRequestParser). This method receives the parsed header fields, validates the WebSocket-specific headers, computes the accept hash, and sends the 101 Switching Protocols response.
RFC 6455 handshake summary:
resource - The URL resource path.headerFields - The header fields of the HTTP request message
(keys must be lowercase).subProtocols - The list of sub-protocols supported by this server,
null for none.doFailForUnsupportedSubProtocol - Flag indicating a WebSocketException is thrown if the
client doesn't request any of our supported protocols.IOException - For failures.WebSocketException - For exceptions relating to Web Sockets (protocol, etc).Phantom® and NetPhantom® are registered trademarks of Mindus SARL.
© 2026 Mindus SARL. All rights reserved.