Sign in

How to use websocket message event monitoring gracefully

Scard edited in Tue, 20 Sep 2022

I use flutter to write an IM communication app similar to wechat, which has a friend list and a conversation page. My reentry page initializes the connection of websocket and listens for the message (using Web)_ socket_ Channel plug-in (link description)

The code is as follows:

void initConnect() async {
  var channel = IOWebSocketChannel.connect("ws://localhost:1234");
  channel.stream.listen((message) {

The previous method is to create a connection on the list page, destroy the connection on the list page when entering the session page, and create a new connection on the session page again. The same is true when exiting.

How can I realize that I only need to create a connection, and can receive listening messages on both the list page and the session page.

2 Replies
commented on Tue, 20 Sep 2022

flutter event_ Let's see how you can monitor

commented on Tue, 20 Sep 2022

I also want to know this question. Because I'm doing a socket communication, I just met