Skip to content

Frequently asked questions

Marcel Prestel edited this page Mar 26, 2018 · 7 revisions

Interesting wiki pages which might help you

Question overview

Questions

I'm getting the exception WebsocketNotConnectedException. What should I do?

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:

  1. Check, if the connection is open and ready to send messages with isOpen()
  2. Use the blocking method connectBlocking(), which is blocking till a connection is established (or an error occurred)

How can I add additional headers to my WebSocketClient connection?

You can add additional headers (like Origin or Cookie) to your handshake, please check out this example here.

How can I add additional headers to my WebSocketServer response?

You can add additional headers (like Access-Control-Allow-Origin) to your handshake, please check out this example here.

How can I get a specific header in my WebSocketClient?

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" );
}

How can I get a specific header in my WebSocketServer?

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" );
}