latest shelf and add new lints (#29)
7 files changed
tree: 1cf829a55f0d264a275cedfa95b90ed48e155b67
- .github/
- lib/
- test/
- .gitignore
- .test_config
- analysis_options.yaml
- CHANGELOG.md
- LICENSE
- pubspec.yaml
- README.md
README.md
Web Socket Handler for Shelf
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}');
});
}