Clone this repo:
  1. 0a85e41 Fix deprecated constant. (#9) by Lasse R.H. Nielsen · 6 weeks ago master 0.2.2+2
  2. 107c312 Remove upper case constants (#6) by Lasse R.H. Nielsen · 9 weeks ago 0.2.2+1
  3. 8cbd4e1 Add Travis-CI support (#5) by Kevin Moore · 5 months ago
  4. d50ac26 Make package strong, also add analysis options file (#4) by Keerti Parthasarathy · 10 months ago
  5. c87aa8a Revert "Make package strong, also add analysis options file" by Keerti Parthasarathy · 10 months ago

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.listen((message) {
      webSocket.add("echo $message");
    });
  });

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