Search packages, repositories and app categories

Package detailsv5.0.3

udp

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

AndroidiOSmacOSWindowsLinux
30-day downloads
7.7K
Likes
76
Pub points
150

Install package

flutter pub add udp

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight and efficient UDP library for Dart, enabling seamless unicast, broadcast, multicast, and loopback communication across platforms. Designed for low-latency networking needs, it provides a simple API to send and receive UDP packets with minimal overhead. Ideal for real-time applications such as gaming, IoT devices, and local network discovery. The library is cross-platform, supporting Android, iOS, macOS, Windows, and Linux, making it versatile for diverse deployment scenarios.

Use cases

  • Real-time game networking
  • IoT device communication
  • Local network discovery
  • Live audio/video streaming
  • Peer-to-peer data transfer

Key features

  • Supports unicast, broadcast, multicast, and loopback
  • Cross-platform compatibility
  • Low-latency packet transmission
  • Simple and intuitive API
  • Efficient memory usage

Suitable for

  • Developers building real-time apps
  • IoT and embedded systems
  • Network protocol experimentation
  • Apps requiring fast local communication

Considerations

  • No built-in reliability or ordering
  • Requires careful handling of packet loss
  • Not suitable for guaranteed delivery
  • Limited error handling
  • Manual management of connection state

Original README

Original README snapshot from the linked source repository. Visit the repository 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.

Categories

Source repository

Projects using this package

No data available yet.