OLD | NEW |
---|---|
(Empty) | |
1 ## Web Socket Handler for Shelf | |
2 | |
3 `shelf_web_socket` is a [Shelf][] handler for establishing [WebSocket][] | |
4 connections. It exposes a single function, [webSocketHandler][], which calls an | |
5 `onConnection` callback with a [CompatibleWebSocket][] object for every | |
6 connection that's established. | |
7 | |
8 [Shelf]: pub.dartlang.org/packages/shelf | |
9 | |
10 [WebSocket]: https://tools.ietf.org/html/rfc6455 | |
11 | |
12 [webSocketHandler]: https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/ shelf_web_socket/shelf_web_socket.webSocketHandler | |
13 | |
14 [CompatibleWebSocket]: https://api.dartlang.org/apidocs/channels/be/dartdoc-view er/http_parser/http_parser.CompatibleWebSocket | |
15 | |
16 ```dart | |
17 import 'package:shelf/shelf_io.dart' as shelf_io; | |
18 import 'package:shelf_web_socket/shelf_web_socket.dart'; | |
19 | |
20 void main() { | |
21 var handler = webSocketHandler((webSocket) { | |
22 webSocket.listen((message) { | |
23 webSocket.add("echo $message"); | |
24 }); | |
25 }); | |
26 | |
27 shelf_io.serve(handler, 'localhost', 8080).then((server) { | |
28 print('Serving at ws://${server.address.host}:${server.port}'); | |
29 }); | |
30 } | |
kevmoo
2014/05/20 21:54:49
end block w/ ```
nweiz
2014/05/20 22:17:42
Done.
| |
OLD | NEW |