websocket字符串onmessage,给出java.lang.illegalstateexception:未找到二进制消息处理程序

42fyovps  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(441)

我有一个使用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,但是编译器不喜欢。

x0fgdtte

x0fgdtte1#

您应该定义一个方法来接收二进制消息。例如,

@OnMessage
public void onMessage(byte[] message) {
    ......
}

有关详细信息,请参阅onmessage注解的javadoc。

相关问题