Lightning fast, strongly typed network protocol

Overview

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));
  }
}
Comments
  • PayLoad Type example

    PayLoad Type example

    Hi,

    Cloud you add a payload type example, please? For example, I have a class:

    class GameClient {
       double x;
       double y;
       String uuid;
    }
    

    And I want to broadcast to my clients new class with all my clients:

    class GameStatus {
       List<GameClient> clients;
    }
    

    In this case, I have to use payload types from your documentation(fix me if I'm wrong), but I don't understand how to register a payload class after the defining.

    opened by loothood 2
  • test: get util tests to 100%

    test: get util tests to 100%

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [x] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • chore: release v0.1.0-dev.2 of both UDP and websocket bindings

    chore: release v0.1.0-dev.2 of both UDP and websocket bindings

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [ ] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • chore: update `bolt` to v0.1.0-dev.2

    chore: update `bolt` to v0.1.0-dev.2

    Status

    READY

    Description

    Update bolt to v0.1.0-dev.2

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [x] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • chore(bolt): 0.1.0-dev.2

    chore(bolt): 0.1.0-dev.2

    Status

    READY

    Description

    Release v0.1.0-dev.2 of bolt

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [x] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • feat: support custom bindings

    feat: support custom bindings

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Add support for custom bindings, and provide an UDP and WebSocket version

    Type of Change

    • [x] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [ ] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • feat: improve example

    feat: improve example

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Type of Change

    • [x] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [ ] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • docs: improve documentation

    docs: improve documentation

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [x] ๐Ÿ“ Documentation
    • [ ] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • ConnectionTimeout on the server must be optional

    ConnectionTimeout on the server must be optional

    Hi, Thank you for the project. Very helpful

    On the server side of your project there is a code:

    packets.listen((packet) {
          final connection = _findExistingConnection(packet.address) ??
              Connection(clientSalt: 0, serverSalt: 0, address: packet.address);
          if (_connectionTimers[connection] != null) {
            _connectionTimeout(connection);
          }
        });
    

    I'm trying to use the server in broadcast mode and I faced an issue: if my client does not send any to the server for 5 sec, the server initials the client disconnection.

    I have a step-based game. And the client has 30 secs to think before the moving. I don't send any action to the server during that time. All the game states got from the server in broadcast mode. But my client disconnects all the time if there are no messages from the client for 5 secs. Could you make _connectionTimeout an optional parameter, please?

    opened by loothood 1
  • test: increase test coverage

    test: increase test coverage

    Status

    READY/IN DEVELOPMENT/HOLD

    Description

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [ ] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [x] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
  • feat!: migrate away from `mason_logger`

    feat!: migrate away from `mason_logger`

    Status

    READY

    Description

    Because mason_logger depends on dart:io, we had to migrate to our own Logger. So we just copied it over and removed the features we dont need.

    Type of Change

    • [ ] โœจ New feature (non-breaking change which adds functionality)
    • [ ] ๐Ÿ› ๏ธ Bug fix (non-breaking change which fixes an issue)
    • [x] โŒ Breaking change (fix or feature that would cause existing functionality to change)
    • [ ] ๐Ÿงน Code refactor
    • [ ] โœ… Build configuration change
    • [ ] ๐Ÿ“ Documentation
    • [ ] ๐Ÿ—‘๏ธ Chore
    opened by wolfenrain 0
Releases(bolt_websocket_binding-v0.1.0-dev.2)
Owner
Jochum van der Ploeg
Jochum van der Ploeg
The world needs more Lightning!

10101 (a.k.a TenTenOne) Dependencies This project requires Flutter and Rust. Rust toolchain can be installed via Rustup. In order to setup Flutter (as

ItchySats 15 Dec 31, 2022
Dart / Flutter package that allows discovering network devices in local network (LAN).

lan_scanner Dart / Flutter package that allows discovering network devices in local network (LAN). Note: This library is intended to be used on Class

null 12 Dec 9, 2022
A Dart/Flutter package to perform network calls. It uses Isolates to perform network calls on Dart VM environments and WebWorkers on Web.

ArDriveHTTP ArDriveHTTP is a package to perform network calls for ArDrive Web. It uses Isolates to perform network calls on Dart VM environments and W

AR.IO 2 Dec 15, 2022
Shared preferences typed - A type-safe wrapper around shared preferences, inspired by ts-localstorage

Typed Shared Preferences A type-safe wrapper around shared_preferences, inspired

Philipp Bauer 0 Jan 31, 2022
SurrealDB client written in pure dart. auto reconnect, typed functions

SurrealDB Client For Dart & Flutter SurrealDB client for Dart and Flutter. Quick Start import 'package:surrealdb/surrealdb.dart'; void main(List<Stri

Duhan BALCI 10 Dec 18, 2022
A simple dart library for extracting the Open Graph protocol on a web pages

ogp_data_extract A simple dart library for extracting the Open Graph protocol on

KINTO 0 Jan 12, 2022
Dart Implementation of the ISO-8583 banking protocol.

Dart Implementation of the ISO-8583 banking protocol. Supports 03xx message class (File Actions Message - 1987) and is compatible with most PoS device

Mahdi K. Fard 11 Dec 8, 2022
UHI is envisioned as an open protocol for various digital health services.

UHI is envisioned as an open protocol for various digital health services. UHI Network will be an open network of End User Applications (EUAs) and participating Health Service Provider (HSP) applications. UHI will enable a wide variety of digital health services between patients and health service providers (HSPs) including appointment booking, teleconsultation, service discovery and others

National Health Authority 62 Jan 5, 2023
A Dart SDK for interacting with a Minecraft server using the RCON protocol.

A Dart SDK for interacting with a Minecraft server using the RCON protocol. Package on pub.dev Features Provides an API to connect to, log in to, send

Aidan Lok 2 Oct 4, 2022
Flutter Client for the stability.ai GRPC protocol, should be compatible with grpc.stability.ai and hafriedlander/stable-diffusion-grpcserver

idea2art This is idea2.art, a Flutter client for the stability.ai GRPC API for Stable Diffusion. It's usable both with the cloud-based grpc.stability.

Hamish Friedlander 9 Dec 5, 2022
Simple and fast Entity-Component-System (ECS) library written in Dart.

Fast ECS Simple and fast Entity-Component-System (ECS) library written in Dart. CPU Flame Chart Demonstration of performance for rotation of 1024 enti

Stanislav 8 Nov 16, 2022
Lucifer is a fast, light-weight web framework in dart.

Lucifer Lightbringer Lucifer is a fast, light-weight web framework in dart. It's built on top of native HttpServer to provide a simple way to fulfill

Salman S 22 Jan 2, 2023
Create dart data classes easily, fast and without writing boilerplate or running code generation.

Dart Data Class Generator Create dart data classes easily, fast and without writing boilerplate or running code generation. Features The generator can

null 186 Feb 28, 2022
Fast math TeX renderer for Flutter written in Dart.

CaTeX is a Flutter package that outputs TeX equations (like LaTeX, KaTeX, MathJax, etc.) inline using a widget and Flutter only - no plugins, no web v

simpleclub 56 Nov 14, 2022
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

HiveDB 3.4k Dec 30, 2022
Flutter makes it easy and fast to build beautiful apps for mobile and beyond

Flutter is Google's SDK for crafting beautiful, fast user experiences for mobile, web, and desktop from a single codebase. Flutter works with existing

Flutter 148.2k Jan 8, 2023
QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter.

QR.Flutter is a Flutter library for simple and fast QR code rendering via a Widget or custom painter. Need help? Please do not submit an issue for a "

Yakka 614 Jan 8, 2023
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

HiveDB 3.4k Dec 30, 2022
A fast, extra light and synchronous key-value storage to Get framework

get_storage A fast, extra light and synchronous key-value in memory, which backs up data to disk at each operation. It is written entirely in Dart and

Jonny Borges 257 Dec 21, 2022