带有stomp的实时数据在android中不起作用

时间:2018-10-27 16:02:28

标签: java android spring react-native stomp

我正在将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 }}
    />

0 个答案:

没有答案