websocket 字符串 onMessage,给出 java.lang.IllegalStateException:未找到二进制消息处理程序
websocket string onMessage, gives java.lang.IllegalStateException: Binary message handler not found
我有一个使用 javax.websocket 的 websocket 设置,它似乎可以连接,但不会工作,它一直显示 java.lang.IllegalStateException:未找到二进制消息处理程序
final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
Session session = webSocketContainer.connectToServer(new Endpoint() {
@Override
public void onError(Session session, Throwable thr) {
// TODO Auto-generated method stub
super.onError(session, thr);
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onError()");
thr.printStackTrace();
}
@Override
public void onOpen(Session session, EndpointConfig EndpointConfig) {
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onOpen()");
try {
//send login details
//login:<deviceid>:<secret>\n
session.getBasicRemote().sendText("login:"+deviceid+":"+secret+"\n");
}
catch(Exception ex){
System.err.println("Exception=" + ex.toString());
ex.printStackTrace();
}
}
@OnMessage
public void onMessage(String message) {
System.out.println("Received message: "+message);
}
@Override
public void onClose(Session session, CloseReason closeReason) {
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onClose()");
}
}, ClientEndpointConfig.Builder.create().build(), URI.create("wss://client.pushover.net/push"));
我试过 ByteBuffer,但编译器不喜欢。
您应该定义一个方法来接收二进制消息。例如,
@OnMessage
public void onMessage(byte[] message) {
......
}
我有一个使用 javax.websocket 的 websocket 设置,它似乎可以连接,但不会工作,它一直显示 java.lang.IllegalStateException:未找到二进制消息处理程序
final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
Session session = webSocketContainer.connectToServer(new Endpoint() {
@Override
public void onError(Session session, Throwable thr) {
// TODO Auto-generated method stub
super.onError(session, thr);
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onError()");
thr.printStackTrace();
}
@Override
public void onOpen(Session session, EndpointConfig EndpointConfig) {
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onOpen()");
try {
//send login details
//login:<deviceid>:<secret>\n
session.getBasicRemote().sendText("login:"+deviceid+":"+secret+"\n");
}
catch(Exception ex){
System.err.println("Exception=" + ex.toString());
ex.printStackTrace();
}
}
@OnMessage
public void onMessage(String message) {
System.out.println("Received message: "+message);
}
@Override
public void onClose(Session session, CloseReason closeReason) {
System.out.println("checkerWindow.DownloadMessages().new Endpoint() {...}.onClose()");
}
}, ClientEndpointConfig.Builder.create().build(), URI.create("wss://client.pushover.net/push"));
我试过 ByteBuffer,但编译器不喜欢。
您应该定义一个方法来接收二进制消息。例如,
@OnMessage
public void onMessage(byte[] message) {
......
}