我正在将stomp用于我的react native应用程序以获取服务器位于java(java spring)上的实时数据。
一切都可以在iOS上使用,但在android上我什至看不到任何连接。
可能是什么问题?我以为这可能是localHost端口问题...
this is the library im using for the stomp
这是我的代码:
sendMessage = (msg) => {
const userId = this.props.profile.id
this.clientRef.sendMessage('/app/hello/' + userId, msg);
}
onMessage = (msg) => {
console.log('msg!');
this.setState({
gaugeStats: msg.gaugeStats
})
this.setState({
generalStats: msg.generalStats
})
console.log(msg);
}
onConnect = () => {
console.log('connect!');
setInterval(() => {
this.sendMessage('hello again')
}, 1000)
}
onDisconnect = (msg) => {
console.log("Disconnect");
}
渲染:
<View style={{ flex: 1 }}>
<SockJsClient url='http://localhost:9000/gs-guide-websocket' topics={['/topic/greetings/' + userId]}
onConnect={this.onConnect}
onMessage={this.onMessage}
onDisconnect={this.onDisconnect}
ref={(client) => { this.clientRef = client }}
/>