shelf_web_socket 3.0.0 copy "shelf_web_socket: ^3.0.0" to clipboard
shelf_web_socket: ^3.0.0 copied to clipboard

A shelf handler that wires up a listener for every connection.

pub package package publisher

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

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}');
  });
}
125
likes
160
points
5.74M
downloads

Publisher

verified publishertools.dart.dev

Weekly Downloads

A shelf handler that wires up a listener for every connection.

Repository (GitHub)
View/report issues
Contributing

Topics

#server #shelf

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

shelf, stream_channel, web_socket_channel

More

Packages that depend on shelf_web_socket