Skip to content

Instantly share code, notes, and snippets.

@kika
Last active August 2, 2022 20:04
Show Gist options
  • Save kika/5e22e2714a43f0225823cd46f887e4be to your computer and use it in GitHub Desktop.
Save kika/5e22e2714a43f0225823cd46f887e4be 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() {
wsAPI()
.then((_) => print('Great success!'))
.catchError((_) => print('Miserable failure'));
}
Future<void> wsAPI() 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;
}
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