WSS server/client/jetty example

80 Views Asked by At

WebSocket noob...

Anyone have a link to a complete jetty 11/12 example with working secure websocket server/client?

I've followed many separate server examples and client examples but there's always an issue whether its an SSL handshake or frame length error or close no_error EoFException. None of them have a complete example, including all dependencies with versions.

Edit: For the down voters... I realise this a broad question. Feel free point me to a better forum to ask this type of question. I figured asking for a eg. link to a working github project would be better than spamming SO with questions every time I hit a problem with broken examples.

1

There are 1 best solutions below

2
Joakim Erdfelt On

This is an overly broad question.

See https://github.com/jetty/jetty-examples/tree/12.0.x/embedded

Look at either of the Jetty 12 sub-projects

  • ee10-websocket-jakarta-api
  • ee10-websocket-jetty-api

These contain the examples you are looking for.

In short, you'll need for the server side ...

  • ServerConnector configured to support whatever "secure" connection you want (https / wss / http1 / http2 / http3 / etc)
  • A context that can receive the request.
  • The context configured to accept WebSocket upgrades.
  • The websocket upgrade configured (with a type of WebSocketCreator depending on chosen technology / APIs) that specifies what path should respond with what websocket endpoint.

For the client side you'll need ...

  • a WebSocketClient (of the type appropriate for your chosen websocket technology / API).
  • a declared WebSocket endpoint that the client uses to receive websocket frames/messages/ping/pong
  • use the WebSocketClient to establish the Request parameters.
  • connect with the Request object and the websocket endpoint.
  • wait for connect (usually seen as a CompletableFuture.get())