FLUTTER ECOSYSTEM

xenoken/udp

Dart용 가벼운 UDP 라이브러리.

udp 프로젝트 이미지
Stars
49
Forks
22
최근 푸시(UTC)
2022. 3. 27.
프로젝트 상태
활성
Ken Ekeoha GitHub avatar
GITHUB User

Ken Ekeoha ↗

언어Dart

기술 주제

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개
  • pedantic개발 의존성^1.11.1
  • test개발 의존성^1.17.8

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

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.