commit | 0f3c6256322f34b6a5b5f8312dce5ff3cf02b010 | [log] [tgz] |
---|---|---|
author | Kevin Moore <kevmoo@google.com> | Sat Jul 20 16:05:13 2019 -0700 |
committer | Kevin Moore <kevmoo@users.noreply.github.com> | Sat Jul 20 16:21:35 2019 -0700 |
tree | 4ddd10703f71e5505bfdb68f638d2cecb680d4fa | |
parent | 0e0438865c3b799eb558925924b79d74442bde10 [diff] |
Support the latest pkg:http (dev dependency)
shelf_web_socket
is a Shelf handler for establishing WebSocket connections. It exposes a single function, webSocketHandler, which calls an onConnection
callback with a WebSocketChannel object for every connection that's established.
import 'package:shelf/shelf_io.dart' as shelf_io; import 'package:shelf_web_socket/shelf_web_socket.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; void main() { var handler = webSocketHandler((webSocket) { webSocket.stream.listen((message) { webSocket.sink.add("echo $message"); }); }); shelf_io.serve(handler, 'localhost', 8080).then((server) { print('Serving at ws://${server.address.host}:${server.port}'); }); }