未连接到 spring websocket 服务器 [英] not connecting to spring websocket server
本文介绍了未连接到 spring websocket 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它没有连接到 websocket 服务器.我正在使用 webstomp-client 来响应 native.请帮帮我!这是我的代码,
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))
}
和日志...
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
提前致谢.
推荐答案
遇到了同样的问题.必须使用以下命令实现自定义 WebSocketHandlerDecorator:
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);
}
基于 https://github.com/facebook/react-native/issues/12731
这篇关于未连接到 spring websocket 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文