bad_socket 0.1.1 copy "bad_socket: ^0.1.1" to clipboard
bad_socket: ^0.1.1 copied to clipboard

Add constrains to your Socket to simulate realworld network connections.

example/bad_socket_example.dart

import 'dart:io';

import 'package:bad_socket/bad_socket.dart';

Future<int> startLocalEchoServer() async {
  final server = await ServerSocket.bind('0.0.0.0', 0);
  server.listen((socket) {
    final badSocket = BadSocket.wrap(
      socket,
      writeLatency: 100,
      writeLoss: 0.2,
    );
    badSocket.listen((data) {
      print('Server send: $data');
      badSocket.add(data);
      badSocket.flush();
    });
  });
  return server.port;
}

main() async {
  final port = await startLocalEchoServer();

  final client = await Socket.connect('127.0.0.1', port);
  client.listen((data) {
    print('Client recv: $data');
  });

  while (true) {
    final data = 'hello world'.runes.toList();
    data.shuffle();
    await Future.delayed(Duration(seconds: 1));
    print('Client send: $data');
    client.add(data);
    await client.flush();
  }
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Add constrains to your Socket to simulate realworld network connections.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on bad_socket