简体   繁体   中英

flutter connection to ratchet websocket

I am trying to connect flutter app to PHP ratchet websocket. this socket work correctly in web with js WebSocket connection. in flutter i use web_socket_channel package and it can send message but it cant receive any message in listen function. my code:

  channel = WebSocketChannel.connect(
    Uri.parse('wss://aftablearn.com/ws'),
  );

  channel.stream.listen(
    (message) {
      print('message');
      print(message);
    },
    onDone: () {
      print("Web socket is closed");
    },
    onError: (error) {
      print(error.toString());
    },
  );

I'm not sure if you mean this: in Ratchet's documentation they show us this:

foreach ($this->clients as $client) {
    if ($from !== $client) {
          $client->send($msg);
    }
}

this works like broadscast, cast to everyone except your device. try this:

foreach ($this->clients as $client) {
    $client->send($msg);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM