Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtyxtyx/bad_socket
Add constrains to your Socket to simulate realworld network connections.
https://github.com/xtyxtyx/bad_socket
dart dartlang socket
Last synced: about 2 months ago
JSON representation
Add constrains to your Socket to simulate realworld network connections.
- Host: GitHub
- URL: https://github.com/xtyxtyx/bad_socket
- Owner: xtyxtyx
- License: mit
- Created: 2019-08-13T12:23:29.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-13T12:39:27.000Z (over 5 years ago)
- Last Synced: 2023-08-20T21:28:00.627Z (over 1 year ago)
- Topics: dart, dartlang, socket
- Language: Dart
- Homepage: https://pub.dev/packages/bad_socket
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Api
```dart
BadSocket.wrap(Socket socket, {
int readLatency,
int readLoss,
int writeLatency,
int writeLoss,
});
```## Usage
Basic example:
```dart
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:
```dart
import 'dart:io';import 'package:bad_socket/bad_socket.dart';
Future 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][tracker].
[tracker]: https://github.com/xtyxtyx/bad_socket/issues