Flutter and Socket.io: No reaction from code, no errors, unable to debug

Viewed 334

I'm creating an app which should trigger a longer process in my nodejs server whereas the app should receive progress updates via socket.io.

The node server with socket.io works fine, I already tested it with a web client in the browser. However, I can't get the flutter code of the socket_io_client 1.0.2 package to execute in my flutter app.

This code is inside a method which is called once a user presses a button:

 try {
print("step 1");
IO.Socket socket = IO.io('http://localhost:3000',
    OptionBuilder().setTransports(['websocket']).build());

socket.on('connect', (_) {
  print('connect: ${socket.id}');
  socket.emit('process1', json.encode(_req));
});

socket.on('progress', (data) => print(data));
socket.onDisconnect((_) {
  print('disconnect');
  _finished = true;
});
} catch (e) {
  print(e);
  print("error");
}
print("step 2");

When clicking the button, the method executes, but not the socket part. In the console, I immediately get

step 1
step 2

but nothing else happens: The console logs the test statements immediately and the server never notices any incoming connections ... it is as the socket.io related code is just never executed. No errors, no console messages, nothing!

Does anyone have an idea why the codes behaves like this, why nothing happens?

Flutter (Channel stable, 2.10.4) socket_io_client: ^1.0.2

1 Answers
Related