bolt

Creator: coderz1093

Last updated:

0 purchases

bolt Image
bolt Images

Languages

Categories

Add to Cart

Description:

bolt

Bolt is a network protocol to send and receive strongly typed data objects








Documentation 📝 #
For documentation about Bolt, see the docs section.
An example of Bolt can be found in the example directory.
Quick Start 🚀 #
Prerequisites 📝 #
In order to start using Bolt you must have the Dart SDK installed on your machine.
Installing 🧑‍💻 #
Add bolt to your pubspec.yaml:
# 📦 Install bolt from pub.dev
dart pub add bolt
copied to clipboard
Creating a shared Data Object 💿 #
Create a shared DataObject for the client and server:
class Ping extends DataObject {
const Ping(this.timestamp);

final int timestamp;

@override
List<Object?> get props => [timestamp];

static void register(BoltRegistry registry) {
registry.registerObject(
100,
DataResolver<Ping>(Ping.new, [
Argument.positional<Ping, int>((d) => d.timestamp, type: uint32),
]),
);
}
}
copied to clipboard
Creating a Server 🏁 #
Define a server, register the data object and listen to messages:
class ExampleServer extends BoltServer {
ExampleServer(super.address, {required super.bindings}) {
Ping.register(registry);

on(_onPinged);
}

void _onPinged(Message<Ping> message) {
// Do something on ping ...
}

@override
Future<bool> verifyAuth(Connection connection, String token) async {
return token == 'super_secure_token';
}
}
copied to clipboard
Creating a Client ✨ #
Define the client, register the data object and implement the onConnected method:
class ExampleClient extends BoltClient {
ExampleClient(super.address, {super.server, required super.binding}) {
Ping.register(registry);
}

@override
void onConnected() {
send(Ping(DateTime.now().millisecondsSinceEpoch));
}
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.