RawApiClient class

A simple socket-based API client to connect to a port on a host server.

Constructors

RawApiClient({required int port, required String host, int idWidth = 4, void onConnect(Socket socket)?, void onReceive(Socket socket, Uint8List data)?, void onDisconnect(Socket socket)?})
Create a new RawApiClient given a port and a host. Callbacks can be optionally provided.

Properties

hasConnected bool
True if the client has established a connection with the server.
no setter
hashCode int
The hash code for this object.
no setterinherited
host String
Host to connect to.
final
idWidth int
The number of bytes to reserve for the endpoint id.
final
onConnect → void Function(Socket socket)?
A callback passing the server Socket when a connection is first established.
final
onDisconnect → void Function(Socket socket)?
A callback passing the server Socket when the client disconnects from the server.
final
onReceive → void Function(Socket socket, Uint8List data)?
A callback passing the server Socket and any sent data as a Uint8List coming from the server.
final
port int
Port to connect to.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

connect({Duration? timeout}) Future<void>
Attempt to make a connection with the remote server.
disconnect() → void
Disconnect from the remote server.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendRequest(ApiRequest request) → void
Send a request to the server in the form of an ApiRequest.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited