Java Reference
In-Depth Information
How do WebSockets work
To initiate a WebSocket session, the client must send an HTTP request with an Upgrade:
websocket header field. This informs the server that the peer client has asked the server
to switch to the WebSocket protocol.
Note
You may notice that the same happens in WildFly for Remote EJBs; the initial connection
is made using an HTTP request, and is later switched to the remote protocol thanks to the
Upgrade mechanism. The standard Upgrade header field can be used to handle any pro-
tocol, other than HTTP, which is accepted by both sides (the client and server). In WildFly,
this allows you to reuse the HTTP port ( 80 / 8080 ) for other protocols and therefore min-
imise the number of required ports that should be configured.
If the server can "understand" the WebSocket protocol, the client and server then proceed
with the handshaking phase. They negotiate the version of the protocol, exchange security
keys, and if everything goes well, the peers can go to the data transfer phase. From now on,
the communication is only done using the WebSocket protocol. It is not possible to ex-
change any HTTP frames using the current connection. The whole life cycle of a connec-
tion can be summarized in the following diagram:
A sample HTTP request from a JavaScript application to a WildFly server would look sim-
ilar to this:
Search WWH ::




Custom Search