搜尋套件、儲存庫與 APP 分類

套件詳情v5.0.3

udp

輕量、高效且易用的 Dart UDP 庫。支援單播、廣播、組播和迴圈通訊。

AndroidiOSmacOSWindowsLinux
近 30 天下載
7730
喜歡數
76
Pub 分數
150

安裝套件

flutter pub add udp

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量且高效的 Dart UDP 庫,可在跨平台環境中實現無縫的單播、廣播、組播和迴圈通訊。專為低延遲網路需求設計,提供簡單的 API 來發送和接收 UDP 資料包,開銷極小。適用於即時應用,如遊戲、物聯網裝置和本地網路發現。該庫支援跨平台,相容 Android、iOS、macOS、Windows 和 Linux,適用於多樣化的部署情境。

適用情境

  • 實時遊戲網路
  • 物聯網設備通訊
  • 本地網絡發現
  • 即時音頻/視頻串流
  • 點對點資料傳輸

主要特色

  • 支援單播、廣播、組播和回環
  • 跨平台相容性
  • 低延遲資料包傳輸
  • 簡單直覺的 API
  • 高效的記憶體使用

適合對象

  • 開發即時應用的開發者
  • 物聯網和嵌入式系統
  • 網路協定實驗
  • 需要快速本地通訊的應用程式

使用建議

  • 無內建的可靠性或順序
  • 需要謹慎處理封包遺失
  • 不適用於保證送達
  • 有限的錯誤處理
  • 手動管理連接狀態

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。