runStompExample function
Future<void>
runStompExample(
)
Implementation
Future<void> runStompExample() async {
// Create two hosts - one will be the server, one will be the client
final serverHost = await createHost('server');
final clientHost = await createHost('client');
// Start the STOMP server
final stompService = await serverHost.addStompService(
options: const StompServiceOptions.serverEnabled(
serverName: 'dart-libp2p-stomp-example/1.0',
),
);
// Give the server a moment to start
await Future.delayed(const Duration(milliseconds: 100));
// Connect client to server
final client = await clientHost.connectStomp(
peerId: serverHost.id,
hostName: 'example.com',
);
// Example 1: Simple message sending
await demonstrateSimpleMessaging(client);
// Example 2: Subscriptions and message delivery
await demonstrateSubscriptions(client);
// Example 3: Transactions
await demonstrateTransactions(client);
// Example 4: Server-side message broadcasting
await demonstrateServerBroadcast(stompService, client);
// Clean up
await client.close();
await stompService.stop();
await serverHost.close();
await clientHost.close();
}