air_link_core 0.2.1 copy "air_link_core: ^0.2.1" to clipboard
air_link_core: ^0.2.1 copied to clipboard

Core LAN communication framework.

example/air_link_core_example.dart

import 'dart:io';
import 'package:air_link_core/air_link_core.dart';

void main() async {
  // Start the server (listener)
  final port = 8080;
  final sessionStream = await Lan.listen(port: port);
  print('Listening for connections on port $port...');

  sessionStream.listen((session) {
    print('Client connected from ${session.peer.id}');
    
    session.peer.onMessage.listen((message) {
      print('Received from client: $message');
      
      // Echo it back
      session.peer.sendText('Echo: $message');
    });
  });

  // Client connects
  await Future.delayed(Duration(seconds: 1));
  print('Client connecting to localhost:$port...');
  
  final clientSession = await Lan.connect('127.0.0.1', port: port);
  print('Connected! Sending message...');
  
  clientSession.peer.onMessage.listen((message) {
    print('Received from server: $message');
    
    // Cleanup and exit after receiving echo
    Lan.stop();
    clientSession.end();
    exit(0);
  });
  
  await clientSession.peer.sendText('Hello from air_link_core!');
}
0
likes
150
points
145
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Core LAN communication framework.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on air_link_core