not connecting to spring websocket server

别来无恙 提交于 2019-12-11 15:24:18

问题


It is not connecting to the websocket server.I am using webstomp-client for react native.Plz, help me ! Here is my code,

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))

}

and logs...

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

Thanks in advance.


回答1:


Got the same issue. Had to implement a custom WebSocketHandlerDecorator with:

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 \00 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);
}

Based on https://github.com/facebook/react-native/issues/12731



来源:https://stackoverflow.com/questions/47591812/not-connecting-to-spring-websocket-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!