Created with <3 with dartpad.dev.
Last active
August 2, 2022 20:04
-
-
Save kika/5e22e2714a43f0225823cd46f887e4be to your computer and use it in GitHub Desktop.
resonating-destiny-0416
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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