'Flutter SocketIo Client TimeOut

I'm trying to add socket io to a flutter project. I'm using socket_io_client 2.0.0-beta.4-nullsafety.0 but when I try to connect to server's socket it just refuse the connection and throw a timeout error.

Here's the code im using:

 _connectSocket()  {
 Socket socket = io('SERVER IP', 
OptionBuilder()
.enableAutoConnect()
  .build()
);
socket.onConnecting((data) => print("conecting socket..."));
socket.onConnectError((data) => print("error : "+data.toString()));
socket.onConnectTimeout((data) => print(data.toString()));

}

Has anyone been through this?

Thanks in advance



Solution 1:[1]

socket = IO.io("ip sever",<String, dynamic>{
    "transports": ["websocket"],
    "autoConnect": false,
    'extraHeaders': {'foo': 'bar'},
  }); socket.connect();
  // socket = await IO.io('ip server',
  //     OptionBuilder()
  //         .setTransports(['websocket']).build());
  socket.onConnect((_) => print('connect'));
  socket.onConnect((_) {
    print('connect');
    
  });
  socket.onConnectError((data) => print( 'error : '+ data.toString() ));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1