{"id":18619953,"url":"https://github.com/xtyxtyx/bad_socket","last_synced_at":"2025-07-15T15:36:25.080Z","repository":{"id":56826443,"uuid":"202138637","full_name":"xtyxtyx/bad_socket","owner":"xtyxtyx","description":"Add constrains to your Socket to simulate realworld network connections.","archived":false,"fork":false,"pushed_at":"2019-08-13T12:39:27.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T06:07:59.805Z","etag":null,"topics":["dart","dartlang","socket"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/bad_socket","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtyxtyx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-13T12:23:29.000Z","updated_at":"2019-09-07T12:55:22.000Z","dependencies_parsed_at":"2022-09-13T08:00:42.686Z","dependency_job_id":null,"html_url":"https://github.com/xtyxtyx/bad_socket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtyxtyx%2Fbad_socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtyxtyx%2Fbad_socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtyxtyx%2Fbad_socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtyxtyx%2Fbad_socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtyxtyx","download_url":"https://codeload.github.com/xtyxtyx/bad_socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239412702,"owners_count":19634072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","dartlang","socket"],"created_at":"2024-11-07T04:04:16.766Z","updated_at":"2025-02-18T05:20:25.752Z","avatar_url":"https://github.com/xtyxtyx.png","language":"Dart","readme":"\n## Api\n\n```dart\nBadSocket.wrap(Socket socket, {\n  int readLatency,\n  int readLoss,\n  int writeLatency,\n  int writeLoss,\n});\n```\n\n## Usage\n\nBasic example:\n\n```dart\nimport 'dart:io';\nimport 'package:bad_socket/bad_socket.dart';\n\nmain() async {\n  // 1. Create a normal socket.\n  Socket socket = await Socket.bind('0.0.0.0', 1234);\n\n  // 2. Wrap it.\n  Socket badSocket = BadSocket.warp(socket,\n    writeLatency: 100,\n    writeLoss: 0.15,\n  );\n\n  // 3. Write to this wrapped socket will take effect\n  //    after 100 ms,\n  //    and 15% of write calls will be discarded.\n  badSocket.add([0xCA, 0xFE]);\n}\n```\n\nA complete example:\n```dart\nimport 'dart:io';\n\nimport 'package:bad_socket/bad_socket.dart';\n\nFuture\u003cint\u003e startLocalEchoServer() async {\n  final server = await ServerSocket.bind('0.0.0.0', 0);\n  server.listen((socket) {\n    final badSocket = BadSocket.wrap(\n      socket,\n      writeLatency: 100,\n      writeLoss: 0.2,\n    );\n    badSocket.listen((data) {\n      print('Server send: $data');\n      badSocket.add(data);\n      badSocket.flush();\n    });\n  });\n  return server.port;\n}\n\nmain() async {\n  final port = await startLocalEchoServer();\n\n  final client = await Socket.connect('127.0.0.1', port);\n  client.listen((data) {\n    print('Client recv: $data');\n  });\n\n  while (true) {\n    final data = 'hello world'.runes.toList();\n    data.shuffle();\n    await Future.delayed(Duration(seconds: 1));\n    print('Client send: $data');\n    client.add(data);\n    await client.flush();\n  }\n}\n\n```\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[tracker]: https://github.com/xtyxtyx/bad_socket/issues\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtyxtyx%2Fbad_socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtyxtyx%2Fbad_socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtyxtyx%2Fbad_socket/lists"}