Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wolfenrain/bolt
Lightning fast, strongly typed network protocol
https://github.com/wolfenrain/bolt
dart dart-package dartlang netcode udp
Last synced: 17 days ago
JSON representation
Lightning fast, strongly typed network protocol
- Host: GitHub
- URL: https://github.com/wolfenrain/bolt
- Owner: wolfenrain
- License: mit
- Created: 2022-11-16T22:13:49.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-04T19:39:38.000Z (about 1 year ago)
- Last Synced: 2024-10-14T02:03:19.143Z (25 days ago)
- Topics: dart, dart-package, dartlang, netcode, udp
- Language: Dart
- Homepage:
- Size: 134 KB
- Stars: 43
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
---
## 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](https://github.com/wolfenrain/bolt/tree/main/packages/bolt) | [![pub package](https://img.shields.io/pub/v/bolt.svg)](https://pub.dev/packages/bolt) |
| [bolt_udp_binding](https://github.com/wolfenrain/bolt/tree/main/packages/bolt_udp_binding) | [![pub package](https://img.shields.io/pub/v/bolt_udp_binding.svg)](https://pub.dev/packages/bolt_udp_binding) |
| [bolt_websocket_binding](https://github.com/wolfenrain/bolt/tree/main/packages/bolt_websocket_binding) | [![pub package](https://img.shields.io/pub/v/bolt_websocket_binding.svg)](https://pub.dev/packages/bolt_websocket_binding) |## Documentation 📝
For documentation about Bolt, see the [docs](https://github.com/wolfenrain/bolt/tree/main/docs) section.
An example of Bolt can be found in the [example](https://github.com/wolfenrain/bolt/tree/main/example) directory.
## Quick Start 🚀
### Prerequisites 📝
In order to start using Bolt you must have the [Dart SDK][dart_install_link] installed on your machine.
### Installing 🧑💻
Add `bolt` to your `pubspec.yaml`:
```sh
# 📦 Install bolt from pub.dev
dart pub add bolt
```### Creating a shared Data Object 💿
Create a shared Data Object for the client and server:
```dart
class Ping extends DataObject {
const Ping(this.timestamp);final int timestamp;
@override
List get props => [timestamp];static void register(BoltRegistry registry) {
registry.registerObject(
100,
DataResolver(Ping.new, [
Argument.positional((d) => d.timestamp, type: uint32),
]),
);
}
}
```### Creating a Server 🏁
Define a server, register the data object and listen to messages:
```dart
class ExampleServer extends BoltServer {
ExampleServer(super.address) {
Ping.register(registry);on(_onPinged);
}void _onPinged(Message message) {
// Do something on ping ...
}@override
Future 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:
```dart
class ExampleClient extends BoltClient {
ExampleClient(super.address, {super.server}) {
Ping.register(registry);
}@override
void onConnected() {
send(Ping(DateTime.now().millisecondsSinceEpoch));
}
}
```[dart_install_link]: https://dart.dev/get-dart
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT
[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg
[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis