shelf_web_socket 3.0.0 shelf_web_socket: ^3.0.0 copied to clipboard
A shelf handler that wires up a listener for every connection.
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
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}');
});
}