0

I had been wrote a simple javax websocket app. I'm trying to send data from @OnOpen method via session to client like this

@OnOpen
public void onOpen(Session session) throws IOException {

    session.getBasicRemote().sendText("Client connected");

}

then I'm trying to recieve it, but got undefined on client

        ws.onopen = function(event) {
            document.getElementById('messages').innerHTML = event.message;
        };

or

        ws.onopen = function(event) {
            document.getElementById('messages').innerHTML = event.data;
        };

Could we get it?!

add: also a same thing with @OnError

Nesquik27
  • 234
  • 1
  • 7
  • 18
  • perhaps you should use onmessage handler to get the message. – Vladimir M May 15 '18 at 10:10
  • Yes, I know, but the question is could we do it with these methods and if no what we could do with them – Nesquik27 May 15 '18 at 10:15
  • 1
    for example as per documentation https://developer.mozilla.org/en-US/docs/Web/API/WebSocket onopen event indicates that connection is ready to send/receive the data. it is meaningful, for example, if you are going to send some data from your client, since connection establishment is async event. – Vladimir M May 15 '18 at 10:18
  • Yes, but how we could use it in javax context for practicle things, I also learnt what it's doing, but when I was trying to right something helpful in the code then the result wasn't expected – Nesquik27 May 15 '18 at 10:47

1 Answers1

0

Based on the JSR 356, if you read the OnOpen part, there are parameters like session, configs and path params but there is nothing you get for a message from the client. So maybe you can use path params to get the data?

Guardian
  • 160
  • 1
  • 13