is it possible to send a data when a websocket connection is opened

DPD picture DPD · Aug 30, 2012 · Viewed 17.8k times · Source

I am implementing a Jetty Websocket servlet. When the server receives a new connection, I want to send a message that will be read by websocket's onopen function. I want this message to be sent only during the open and not using the regular connection.SendMessage() function. Is it possible to do that? and how?

Answer

Lewis picture Lewis · Feb 14, 2015

Don't forget the query string. It's valid in WebSocket url.

new Websocket('ws://yoursite.com/path?a=1&b=2&c=3')

Then you can easily parse this url on server side to retrieve the data.