flutter connection to ratchet websocket

Viewed 207

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());
    },
  );
1 Answers

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);
}
Related