dashwire 0.1.0 copy "dashwire: ^0.1.0" to clipboard
dashwire: ^0.1.0 copied to clipboard

Multiplayer networking for Dart games. Transport, session, and tick core.

example/dashwire_example.dart

// Encode a message with the wire primitives, then round-trip a payload
// through the in-process loopback transport.
import 'package:dashwire/dashwire.dart';

Future<void> main() async {
  // Wire primitives are little-endian with varints and length-prefixed
  // strings, and every encoding has a byte-exact golden test.
  final writer = ByteWriter()
    ..writeString('dash')
    ..writeVarUint(300)
    ..writeF32(1.5);
  final bytes = writer.toBytes();

  final reader = ByteReader(bytes);
  print(reader.readString()); // dash
  print(reader.readVarUint()); // 300
  print(reader.readF32()); // 1.5

  // A loopback pair models two connected peers with reliable and unreliable
  // channels; the same code runs over WebSocket or UDP transports.
  final (client, server) = LoopbackConnection.pair();
  final sub = server.messages.listen((m) {
    print('server received ${m.payload.length} bytes on ${m.channel}');
  });

  client.send(Channel.reliable, bytes);
  await Future<void>.delayed(Duration.zero);

  await sub.cancel();
  await client.close();
}
0
likes
160
points
3.05k
downloads

Documentation

API reference

Publisher

verified publisherbdero.dev

Weekly Downloads

Multiplayer networking for Dart games. Transport, session, and tick core.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

web

More

Packages that depend on dashwire