vibe_ipc 0.1.1
vibe_ipc: ^0.1.1 copied to clipboard
Single-instance local IPC for Dart desktop apps. Unix socket, schema-validated requests, retry-safe ids, ready ack and start-if-closed.
import 'package:vibe_ipc/vibe_ipc.dart';
/// Run once to start the server, and again with an argument to send to it:
/// dart run example/vibe_ipc_example.dart
/// dart run example/vibe_ipc_example.dart "hello"
Future<void> main(List<String> args) async {
final path = defaultSocketPath('vibe-ipc-example');
if (args.isEmpty) {
final server = IpcServer(
path,
IpcSchema({
'say': (a) => a['text'] is String ? {'text': a['text']} : null,
}),
(r) async {
print('got: ${r.args['text']}');
return IpcResponse(r.id, true, 'ok', text: 'printed');
},
);
await server.start();
print('listening on $path (Ctrl+C to stop)');
} else {
final launcher =
IpcLauncher(IpcClient(path), () async => throw 'not started');
final out = await launcher
.deliver(IpcRequest(launcher.newId(), 'say', {'text': args.join(' ')}));
print('${out.ok} ${out.code} ${out.text}');
}
}