vmServiceConnect function

  1. @Deprecated('Prefer vmServiceConnectUri')
Future<VmService> vmServiceConnect (
  1. String host,
  2. int port,
  3. {Log log}
)

Implementation

@Deprecated('Prefer vmServiceConnectUri')
Future<VmService> vmServiceConnect(String host, int port, {Log log}) async {
  final WebSocket socket = await WebSocket.connect('ws://$host:$port/ws');
  final StreamController<dynamic> controller = StreamController();
  final Completer streamClosedCompleter = Completer();

  socket.listen(
    (data) => controller.add(data),
    onDone: () => streamClosedCompleter.complete(),
  );

  return VmService(
    controller.stream,
    (String message) => socket.add(message),
    log: log,
    disposeHandler: () => socket.close(),
    streamClosed: streamClosedCompleter.future,
  );
}