Giter Club home page Giter Club logo

bolt's Introduction

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));
  }
}

bolt's People

Contributors

wolfenrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bolt's Issues

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.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.