2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2025-06-26 22:33:12 +00:00
This commit is contained in:
2025-05-27 21:38:56 +03:00
parent 2380baf9ff
commit ef12858dbd
2 changed files with 88 additions and 60 deletions

View File

@ -103,12 +103,32 @@ class WSocket extends ISocket {
Uri.parse("${secure ? 'wss' : 'ws'}://${hostname}:${port}"),
); //binaryType: BinaryType.list);
_state = SocketState.Established;
if (_channel == null)
{
rt.triggerError(AsyncException(ErrorType.Management,
ExceptionCode.HostNotReachable.index, "Can't create WebSocketChannel."));
}
else
{
if (_channel!.closeCode != null)
rt.triggerError(AsyncException(ErrorType.Management,
ExceptionCode.HostNotReachable.index, "WebSocketChannel " + _channel!.closeCode.toString()));
begin();
receiver?.networkConnect(this);
rt.trigger(true);
} catch (ex) {
_channel!.ready.then((x){
_state = SocketState.Established;
begin();
receiver?.networkConnect(this);
rt.trigger(true);
}).onError((ex, s){
rt.triggerError(AsyncException(ErrorType.Management,
ExceptionCode.HostNotReachable.index, ex.toString()));
});
}
} catch (ex) {
rt.triggerError(AsyncException(ErrorType.Management,
ExceptionCode.HostNotReachable.index, ex.toString()));
}