Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xenoken/udp
Lightweight UDP library for Dart.
https://github.com/xenoken/udp
dart networking udp
Last synced: 6 days ago
JSON representation
Lightweight UDP library for Dart.
- Host: GitHub
- URL: https://github.com/xenoken/udp
- Owner: xenoken
- License: bsd-3-clause
- Created: 2019-06-29T02:50:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-27T12:21:20.000Z (over 2 years ago)
- Last Synced: 2024-06-19T00:39:20.121Z (5 months ago)
- Topics: dart, networking, udp
- Language: Dart
- Size: 32.2 KB
- Stars: 47
- Watchers: 6
- Forks: 21
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Lightweight UDP library for Dart.
## Usage
A simple usage example:
```dart
import 'package:udp/udp.dart';main() async {
// creates a UDP instance and binds it to the first available network
// interface on port 65000.
var sender = await UDP.bind(Endpoint.any(port: Port(65000)));
// send a simple string to a broadcast endpoint on port 65001.
var dataLength = await sender.send("Hello World!".codeUnits,
Endpoint.broadcast(port: Port(65001)));
stdout.write("$dataLength bytes sent.");
// creates a new UDP instance and binds it to the local address and the port
// 65002.
var receiver = await UDP.bind(Endpoint.loopback(port: Port(65002)));
// receiving\listening
receiver.asStream(timeout: Duration(seconds: 20)).listen((datagram) {
var str = String.fromCharCodes(datagram.data);
stdout.write(str);
});
// close the UDP instances and their sockets.
sender.close();
receiver.close();
// MULTICAST
var multicastEndpoint =
Endpoint.multicast(InternetAddress("239.1.2.3"), port: Port(54321));
var receiver = await UDP.bind(multicastEndpoint);
var sender = await UDP.bind(Endpoint.any());
receiver.asStream().listen((datagram) {
if (datagram != null) {
var str = String.fromCharCodes(datagram?.data);
stdout.write(str);
}
});
await sender.send("Foo".codeUnits, multicastEndpoint);
await Future.delayed(Duration(seconds:5));
sender.close();
receiver.close();
}
```## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/xenoken/udp/issues