Clone this repo:
  1. 463a948 Update LICENSE by Franklin Yow · 3 months ago master
  2. f7b3c35 Update setup, test oldest supported SDK (#36) by Kevin Moore · 3 months ago
  3. 24fb8a0 release 1.0.1 (#35) by Jacob MacDonald · 3 months ago 1.0.1
  4. aa312d3 udpate for the new Never type in Request.hijack (#34) by Jacob MacDonald · 4 months ago
  5. d2e757b add regular test dev dep (#33) by Jacob MacDonald · 4 months ago 1.0.0

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}');
  });
}