datagram_socket 1.0.0 copy "datagram_socket: ^1.0.0" to clipboard
datagram_socket: ^1.0.0 copied to clipboard

A buffered interface to a UDP socket.

example/example.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:datagram_socket/datagram_socket.dart';

void main() async {
  final serverAddress = (await InternetAddress.lookup('pool.ntp.org')).first;
  final clientSocket = await DatagramSocket.bind(
    serverAddress.type == InternetAddressType.IPv6
        ? InternetAddress.anyIPv6
        : InternetAddress.anyIPv4,
    0,
  );

  final ntpQuery = Uint8List(48);
  ntpQuery[0] = 0x23; // See RFC 5905 7.3

  clientSocket.send(ntpQuery, serverAddress, 123);

  final datagram = await clientSocket.first;

  // Parse `datagram.data`

  clientSocket.close();
}
0
likes
150
points
86
downloads

Publisher

verified publisherdartcommunity.dev

Weekly Downloads

A buffered interface to a UDP socket.

Repository (GitHub)
View/report issues

Topics

#network #socket #udp

Documentation

API reference

License

MIT (license)

More

Packages that depend on datagram_socket