[英]How to get message from javax websocket server when connection has been opened
I had been wrote a simple javax websocket app.我已经写了一个简单的 javax websocket 应用程序。 I'm trying to send data from @OnOpen method via session to client like this
我正在尝试通过会话将数据从 @OnOpen 方法发送到客户端
@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添加:@OnError 也是同样的事情
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.基于JSR 356 ,如果您阅读 OnOpen 部分,则有会话、配置和路径参数之类的参数,但是您从客户端获取的消息没有任何信息。 So maybe you can use path params to get the data?
那么也许您可以使用路径参数来获取数据?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.