udp 3.0.0 copy "udp: ^3.0.0" to clipboard
udp: ^3.0.0 copied to clipboard

outdated

Lightweight, efficient, and easy-to-use UDP library for Dart. Supports Unicast, Broadcast, Multicast and Loopback communications.

Lightweight UDP library for Dart.

Usage #

A simple usage example:

import 'package:udp/udp.dart';


main() async {

  // creates a UDP instance and binds it to the local address and the port 42.
  var sender = await UDP.bind(Endpoint.loopback(port:Port(42)));

  // send a simple string to a broadcast endpoint on port 21.
  var dataLength = await sender.send("Hello World!".codeUnits,
      Endpoint.broadcast(port: Port(21)));

  stdout.write("${dataLength} bytes sent.");

  // creates a new UDP instance and binds it to the local address and the port
  // 39.
  var receiver = await UDP.bind(Endpoint.loopback(port:Port(39)));

  // receiving\listening
  await receiver.listen((datagram) {
    var str = String.fromCharCodes(datagram.data);
    stdout.write(str);
  },Duration(seconds:20));


  // 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());
  
    unawaited(receiver.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.

64
likes
0
pub points
93%
popularity

Publisher

unverified uploader

Lightweight, efficient, and easy-to-use UDP library for Dart. Supports Unicast, Broadcast, Multicast and Loopback communications.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on udp