未连接到Spring Websocket服务器



它没有连接到websocket服务器。我正在使用webstomp-client用于react natival.plz,请帮助我!这是我的代码

componentWillMount() {
  let msg = '';
  const options = {
    debug: true,
    protocols: webstomp.VERSIONS.supportedProtocols()
  }
  this.stompClient = webstomp.client("ws://192.168.3.167:8080/test", options)
  this.stompClient.connect({}, (frame) => {
    console.log("OK")
    this.stompClient.subscribe('/topic/greetings', (greeting) => {
      msg = JSON.parse(greeting.body);
    });
    this.setState({
      connected: true,
      message: msg
    })
  }, (err) => console.log(err))
}

和日志...

Opening Web Socket...
webstomp.js:243 Web Socket Opened...
webstomp.js:243 >>> CONNECT
accept-version:1.2,1.1,1.0
heart-beat:10000,10000

预先感谢。

遇到了同样的问题。必须使用以下方式实现自定义Websockethandlerderderderder:

public void handleMessage(final WebSocketSession session, final WebSocketMessage<?> message) throws Exception {
    if (message instanceof TextMessage) {
        TextMessage msg = (TextMessage) message;
        String payload = msg.getPayload();
        // only add 0 if not present (iOS / Android)
        if (!payload.substring(payload.length() - 1).equals("u0000")) {
            super.handleMessage(session, new TextMessage(payload + "u0000"));
            return;
        }
    }
    super.handleMessage(session, message);
}

基于https://github.com/facebook/react-native/issues/12731

相关内容

  • 没有找到相关文章

最新更新