MessageSocket class
Packages data from a stream into messages, by wrapping messages with a prefixed length (and then
the length reversed and inverted (xor 0xFFF...), for checksum).
Note: I've added locks on sending and receiving, so message integrity should be safe, but you should
still be aware of the potential confusion/mixups inherent to having multiple threads communicate over
a single channel.
- Implementers
Constructors
- MessageSocket.new(Socket sock, {Duration? autoping = const Duration(seconds: 5)})
-
Wraps
sock
, immediately starts reading messages into buffer.
Automatically pings at intervalautoping
(not pinging if autoping is null), flagging connection as broken if the ping fails (which takes like 30 seconds). See ping.
Properties
Methods
-
close(
) → Future< void> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ping(
) → Future< void> -
This ping gets no pong. It relies on the behavior I've so far observed, that if you try to send
data on a broken connection, it times out after 30 seconds or so, flagging the connection as broken
(and aborting any read attempts in progress, btw). The data it sends is an 8 byte big endian -1,
which would otherwise indicate a subsequent message -1 bytes in length (but is discarded as a ping).
-
recvBytes(
{int maxLen = 1000000, bool tryHard = true}) → Future< Uint8List?> - Result of [] simply means an empty message; result of null implies some kind of failure; likely a disconnect. //NEXT Update docs
-
recvString(
{bool? allowMalformed = true, int maxLen = 1000000, bool tryHard = true}) → Future< String?> -
sendBytes(
Uint8List data, {bool important = true}) → Future< bool> -
Send a message.
data
should be a list of bytes, or a string (which will then be encoded with utf-8.)
Throws exception on socket failure.
//DUMMY Doesn't throw. Just keeps going. Should probably fix that.
If notimportant
, and another message is currently being sent, returns false instead of sending the message.
Otherwise, returns true once message has been added to the sock.
-
sendString(
String s, {bool important = true}) → Future< bool> -
See
sendBytes
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited