GitXplorerGitXplorer
w

bolt

public
44 stars
0 forks
4 issues

Commits

List of commits on branch main.
Verified
2b454edfdfbcc7afb05f2aa02919f01d57984e12

test: get util tests to 100% (#7)

wwolfenrain committed 2 years ago
Verified
cb814a75a167bf5ea6f002b7b4e36fb1c8cccf5b

chore: release v0.1.0-dev.2 of both UDP and websocket bindings (#6)

wwolfenrain committed 2 years ago
Verified
df2767f5d5ed5ae73ac33a4b76765f6014e9c978

chore: update `bolt` to v0.1.0-dev.2 (#5)

wwolfenrain committed 2 years ago
Verified
3dac36cd673df6a6e133bb81a4c411d13765b9cb

chore(bolt): 0.1.0-dev.2 (#4)

wwolfenrain committed 2 years ago
Verified
ffdacdd4f88bebc2b832f206fe435d8e9ba4f931

feat: support custom bindings (#3)

wwolfenrain committed 2 years ago
Verified
3fb9ca909fa1c14ee820b4f909d6840ce8e87bf5

docs: improve documentation (#1)

wwolfenrain committed 2 years ago

README

The README file for this repository.

bolt logo

bolt coverage style: very good analysis License: MIT


What is Bolt

Bolt is a network protocol written in Dart to send and receive strongly typed data objects. It is designed to be easy to use and to be as fast as possible.

Bolt is split into two parts, the BoltClient and the BoltServer. They both implement the BoltProtocol, which handles settings up the connection, verifying the connection is secure and sending/receiving data objects.

Everything is abstracted away in these classes, this means that you can implement your own abstraction on top of Bolt by just extending from BoltClient and BoltServer.

Bolt works on the principal of shared code, this means that you write common code that is shared between both server and client.

Packages

Package Pub
bolt pub package
bolt_udp_binding pub package
bolt_websocket_binding pub package

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

Creating a shared Data Object 💿

Create a shared Data Object 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),
      ]),
    );
  }
}

Creating a Server 🏁

Define a server, register the data object and listen to messages:

class ExampleServer extends BoltServer {
  ExampleServer(super.address) {
    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';
  }
}

Creating a Client ✨

Define the client, register the data object and implement the onConnected method:

class ExampleClient extends BoltClient {
  ExampleClient(super.address, {super.server}) {
    Ping.register(registry);
  }

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