-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Frequently asked questions
Marcel Prestel edited this page Mar 26, 2018
·
7 revisions
- I am having problems with secure websockets (wss). What should I do?
- How can I enable SO_REUSEADDR?
- How can I enable TCP_NODELAY?
- How can I attach custom data to a WebSocket?
- How can I reject a handshake as a server?
- How can I use a Sec-WebSocket-Protocol?
- I'm getting the exception
WebsocketNotConnectedException
. What should I do? - How can I add additional headers to my WebSocketClient connection?
- How can I add additional headers to my WebSocketServer response?
- How can I get a specific header in my WebSocketClient?
- How can I get a specific header in my WebSocketServer?
This exception indicates that the connection is not yet established. Due to that reason you are not allowed to send any message to the other endpoint. You can do one of two things to avoid this exception:
- Check, if the connection is open and ready to send messages with
isOpen()
- Use the blocking method
connectBlocking()
, which is blocking till a connection is established (or an error occurred)
You can add additional headers (like Origin
or Cookie
) to your handshake, please check out this example here.
You can add additional headers (like Access-Control-Allow-Origin
) to your handshake, please check out this example here.
When onOpen
is called, the complete handshake received from the server is included in the ServerHandshake
argument.
public void onOpen( ServerHandshake handshake ) {
if (!handshake.hasFieldValue( "Server" )) {
return;
}
String server = handshake.getFieldValue( "Server" );
}
When onOpen
is called, the complete handshake received from the client is included in the ClientHandshake
argument.
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
if (!handshake.hasFieldValue( "Cookie" )) {
return;
}
String cookie = handshake.getFieldValue( "Cookie" );
}