问题
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