Clone this repo:
  1. ff16a50 Merge pull request #14 from dart-lang/grouma-patch-1 by Gary Roumanis · 7 weeks ago master
  2. 4c62e90 Update README.md by Gary Roumanis · 7 weeks ago
  3. 703923a Fix _BinaryFunction typedef to only check arity (#12) by Nate Bosch · 2 months ago 0.2.2+4
  4. 56338f7 chore: set max SDK version to <3.0.0 (#10) by Patrice Chalin · 3 months ago 0.2.2+3
  5. 0a85e41 Fix deprecated constant. (#9) by Lasse R.H. Nielsen · 5 months ago 0.2.2+2

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 CompatibleWebSocket 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';

void main() {
  var handler = webSocketHandler((webSocket) {
    webSocket.stream.listen((message) {
      webSocket.add("echo $message");
    });
  });

  shelf_io.serve(handler, 'localhost', 8080).then((server) {
    print('Serving at ws://${server.address.host}:${server.port}');
  });
}