Air Link Core
The easiest LAN communication framework for Dart & Flutter.
Stop thinking about sockets, packets, and protocols. Start thinking about communication.
await peer.sendText('Hello!');
Quick Start
1. Add the dependency
dependencies:
air_link_core:
git:
url: https://github.com/DarpanAdhikari/air_link_workspace.git
path: packages/air_link_core
2. Start a host
import 'package:air_link_core/air_link_core.dart';
void main() async {
final sessions = await Lan.listen(port: 8080);
sessions.listen((session) {
print('Peer connected: ${session.peer.id}');
session.peer.onMessage.listen((message) {
print('Received: $message');
});
});
}
3. Connect from another device
import 'package:air_link_core/air_link_core.dart';
void main() async {
final session = await Lan.connect('192.168.1.42', port: 8080);
await session.peer.sendText('Hello from Air Link!');
session.peer.onMessage.listen((reply) {
print('Reply: $reply');
});
}
Core Concepts
Peer
await peer.sendText('Hey!'); // Send text
await peer.sendBytes(myBytes); // Send raw bytes
peer.onMessage.listen((msg) {}); // Receive text
peer.onBytes.listen((bytes) {}); // Receive bytes
peer.onDisconnected.listen((_) {}); // Detect disconnection
await peer.disconnect(); // Disconnect
Session
final session = await Lan.connect('192.168.1.42');
print(session.connectedAt);
print(session.peer.id);
session.onDisconnected.listen((_) => print('Lost connection'));
session.onReconnected.listen((_) => print('Reconnected'));
await session.end(); // End the session permanently
Lan
// Host: listen for connections
final sessions = await Lan.listen(port: 8080);
// Client: connect to a host
final session = await Lan.connect('192.168.1.42', port: 8080);
// Instance API for multiple listeners
final lan = Lan();
final stream = await lan.bind(port: 8081);
final peer = await lan.dial('10.0.0.5', port: 8082);
await lan.close();
Heartbeat & Reconnect
final session = Session.start(
'my-peer',
transport,
heartbeat: HeartbeatConfig(
interval: Duration(seconds: 5),
timeout: Duration(seconds: 3),
),
reconnect: ReconnectPolicy(
transportFactory: () async { /* rebuild transport */ },
maxRetries: 3,
baseDelay: Duration(seconds: 1),
),
);
Reliability
| Feature | Status |
|---|---|
| TCP stream framing | ✅ |
| Packet serialization | ✅ |
| Length-prefixed framing | ✅ |
| Partial packet buffering | ✅ |
| Clean disconnection | ✅ |
| Broadcast event streams | ✅ |
| Heartbeat keep-alive (PING/PONG) | ✅ |
| Stale connection detection | ✅ |
| Exponential-backoff reconnect | ✅ |
| Reconnect guard (prevents loops) | ✅ |
Package Ecosystem
| Package | Purpose |
|---|---|
air_link_core |
Connections, peers, sessions, transport |
air_link_secure |
E2EE (ECDSA auth, AES-256-GCM, HKDF) |
air_link_discovery |
Zero-config UDP broadcast discovery |
air_link_stream |
Live data streaming |
air_link_file |
File transfer with progress |
air_link_text |
Rich text messaging |
air_link_rpc |
Request/response RPC |
air_link_mesh |
Multi-hop mesh routing |
air_link_bridge |
HTTP/WebSocket bridge |
air_link_sync |
CRDT state synchronization |
Requirements
- Dart SDK
>=3.0.0 <4.0.0
License
MIT