Search packages, repositories and app categories

GitHub repositoryxenoken/udp

udp

Lightweight UDP library for Dart.

udp project cover
Stars
49
Forks
22
Last push (UTC)
Mar 27, 2022
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

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 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.

Ken Ekeoha GitHub avatar
GitHub author

Ken Ekeoha ↗

LanguagesDart

Categories

Packages published by this repository

Dependencies used

Dependency list 2 items

  • pedanticDevelopment^1.11.1
  • testDevelopment^1.17.8

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗