bad_socket 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 16

Api #

BadSocket.wrap(Socket socket, {
  int readLatency,
  int readLoss,
  int writeLatency,
  int writeLoss,
});

Usage #

Basic example:

import 'dart:io';
import 'package:bad_socket/bad_socket.dart';

main() async {
  // 1. Create a normal socket.
  Socket socket = await Socket.bind('0.0.0.0', 1234);

  // 2. Wrap it.
  Socket badSocket = BadSocket.warp(socket,
    writeLatency: 100,
    writeLoss: 0.15,
  );

  // 3. Write to this wrapped socket will take effect
  //    after 100 ms,
  //    and 15% of write calls will be discarded.
  badSocket.add([0xCA, 0xFE]);
}

A complete example:

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

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.1 #

  • Update description.

0.1.0 #

  • Initial version, created by Stagehand

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bad_socket: ^0.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bad_socket/bad_socket.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
16
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Health issues and suggestions

Fix lib/src/bad_socket_base.dart. (-99.98 points)

Analysis of lib/src/bad_socket_base.dart failed with 30 errors, including:

line 13 col 1: The class 'BadSocket' cannot implement both 'Stream<List

line 13 col 7: Superinterfaces don't have a valid override for 'firstWhere': Stream.firstWhere (firstWhere), Stream.firstWhere (firstWhere).

line 13 col 7: Superinterfaces don't have a valid override for 'lastWhere': Stream.lastWhere (lastWhere), Stream.lastWhere (lastWhere).

line 13 col 7: Superinterfaces don't have a valid override for 'reduce': Stream.reduce (reduce), Stream.reduce (reduce).

line 13 col 7: Superinterfaces don't have a valid override for 'singleWhere': Stream.singleWhere (singleWhere), Stream.singleWhere (singleWhere).

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0