Closed Nabinda closed 1 year ago
What have you tried to handle this exception? Do you have a reproduction you can share?
try {
socket = IOWebSocketChannel.connect(SocketConfig.mainUrl);
_messageController = StreamController<dynamic>.broadcast();
socket.stream.listen(
_onMessageReceived,
onError: onError,
onDone: onDone,
);
} catch (e) {
onError(e);
}
This is how I was trying to handle the issue however it was not working, this issue occurs when you try to connect the socket when device is not connected to internet
@Nabinda could you try?
try {
socket = IOWebSocketChannel.connect(SocketConfig.mainUrl);
await socket.ready; // Show throw if the connection cannot be established.
} catch (e) {
onError(e);
}
@Nabinda could you try?
try { socket = IOWebSocketChannel.connect(SocketConfig.mainUrl); await socket.ready; // Show throw if the connection cannot be established. } catch (e) { onError(e); }
Thanks buddy, it worked for me in case of Server not available. I was intentionally trying to catch this exception but was not able to find any way to do it. It would be great,if any explanation is there regarding await socket.ready;
and why traditional catch is not able to handle this.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101)
When the device is not connected on internet then this issues occurs which cannot be handled