Fix readme URLs
1 file changed
tree: 111ff3a0fc981ae8c6cbff4d347ed2a5cb24bc5c
  1. .gitignore
  2. .test_config
  3. .travis.yml
  4. CHANGELOG.md
  5. LICENSE
  6. README.md
  7. lib/
  8. pubspec.yaml
  9. test/
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}');
  });
}