Skip to content

Instantly share code, notes, and snippets.

@kika
Created August 2, 2022 19:58
Show Gist options
  • Save kika/fe4b25c39df11dd4186682ac940c8bdf to your computer and use it in GitHub Desktop.
Save kika/fe4b25c39df11dd4186682ac940c8bdf to your computer and use it in GitHub Desktop.
resonating-destiny-0416

resonating-destiny-0416

Created with <3 with dartpad.dev.

import 'dart:html';
void main() async {
try {
final socket = await wsConnect('wss://127.0.0.1:7654');
print('${socket.readyState}');
} catch (e) {print(e);}
}
Future<WebSocket> wsConnect(String url) async {
final socket = WebSocket(url);
socket.onError.listen((_) => throw Exception('connection error'));
socket.onClose.listen((_) => throw Exception('connection close'));
return socket;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment