1

Can someone please provide me simple example of webocket client with access token using javax.websocket?

I want to connect to websocket, send message and listen to messages. All messages are in JSON format.

(sorry for dumb question, I'm learning Java, thanks)

javax.websocket client simple example is the very similar, but it doesn't use access token.

Thanks.

Community
  • 1
  • 1

1 Answers1

0

When any websocket client connects to the websocket server, create an access token (random UUID or some thing else) and send it as a callback for the CONNECT frame.

You can store session id to access token mapping in your websocket server to verify the client.

From client side, with each message add this token as part your Json and at the server side verify whether the access token is valid or not. (check whether this session id is matching with the access token that is sent by the client)

Once a client disconnects, you can delete this access token(based on session id) so that you can prevent any misuse of access token.

Karthik
  • 4,950
  • 6
  • 35
  • 65