commit | abae6956e2f7d863a416c99aa031d7fa1a7160a7 | [log] [tgz] |
---|---|---|
author | Nate Bosch <nbosch@google.com> | Wed Dec 09 00:54:17 2020 |
committer | GitHub <noreply@github.com> | Wed Dec 09 00:54:17 2020 |
tree | 8736070b0d06d85d602f5ccede2e2b7422fd4bde | |
parent | 8050a55b16faa5052a3e5d7dcdc170c59b6644f2 [diff] |
Pass a Uri to package:http APIs (#25) Prepare for https://github.com/dart-lang/http/issues/375
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}'); }); }