net library
The network layer: a host and clients over TCP exchanging newline-delimited JSON messages. It depends on nothing else in this package.
Classes
- NetConnection
- One end of a TCP connection carrying NetMessages, one JSON object a line. TCP is a stream, so a message of any size arrives whole and in order.
- NetHost
- The authoritative side: listens on a port, numbers each client that joins and tells the game through onJoin, onMessage and onLeave.
- NetPeer
- A peer of a NetHost: its number and its connection.
Extension Types
- EncodedMessage
- A NetMessage encoded once for the wire: its JSON line, newline included, in UTF-8. One encoding goes to any number of connections (NetConnection.sendEncoded), which only read it.
Functions
-
connectToHost(
String address, {int port = 7777, Duration timeout = const Duration(seconds: 5)}) → Future< NetConnection> -
Connects to a host at
address:port.
Typedefs
-
NetMessage
= Map<
String, Object?> -
A message: a JSON object whose
tnames its type.