Tihomir Meščić Tihomir Meščić - 1 year ago 132
Java Question

Connection timeout using standard JSR356 WebSocket client

I have a Java application that connects to a remote websocket server. As a client, I'm using the standard J2EE JSR356 WebSocket API:


However, I haven't found a way to specify a connection timeout using this API. When I call the connectToServer(...) method, it block until it establishes a connection (which may never happen).

Is there a way to specify a connection timeout using the standard API? If not, are there any workarounds?

Answer Source

Unfortunately, this is not exposed by JSR 356 - WebSocket API for Java. You will need to use implementation feature, such as HANDSHAKE_TIMEOUT in Tyrus (reference implementation). Other implementations will most likely have something similar.

Seems like there is no ticket about this yet in WEBSOCKET_SPEC, so you can add one if you want (I was able to find only issue which is mentioning SSL properties - WEBSOCKET_SPEC-210).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download