void main() async {
// Start a client that connects without the usage of an authentication process
final client1 = Client(
// The realm to connect to
// We choose WebSocket transport
transport: WebSocketTransport(
'wss://...........8080/wss2/',
// if you want to use msgpack instead of JSON just import the serializer
// from package:connectanum/msgpack.dart and use WebSocketSerialization.SERIALIZATION_MSGPACK
Serializer(),
WebSocketSerialization.serializationJson,
{"Sec-WebSocket-Protocol": "wamp"},
));
late Session session1;
try {
// connect to the router and start the wamp layer
session1 = await client1
.connect(
options: ClientConnectOptions(
reconnectCount: 3, // Default is 3
reconnectTime: const Duration(
milliseconds: 200) // default is null, so immediately
// you may add ping pong options here as well
))
.first;
log("Connected>>>");
// if you want to change the options after each reconnect, use this event
client1.onNextTryToReconnect.listen((passedOptions) {
// enlarge the time to wait after each reconnect by 500ms
passedOptions.reconnectTime = Duration(
milliseconds: passedOptions.reconnectTime!.inMilliseconds + 500);
});
// register a method that may be called by other clients
final registered = await session1.register('order');
registered.onInvoke((invocation) => invocation.respondWith());
// subscribe to a topic that my be published by other clients
final subscription = await session1.subscribe('order');
subscription.eventStream!.listen((event) => print(event.arguments![0]));
await subscription.onRevoke.then((reason) =>
print('The server has killed my subscription due to: $reason'));
} on Abort catch (abort) {
// if the serve does not allow this client to receive a session
// the server will cancel the initializing process with an abort
print(abort.message!.message);
}
runApp(const MyApp());
}
void main() async { // Start a client that connects without the usage of an authentication process final client1 = Client( // The realm to connect to // We choose WebSocket transport transport: WebSocketTransport( 'wss://...........8080/wss2/', // if you want to use msgpack instead of JSON just import the serializer // from package:connectanum/msgpack.dart and use WebSocketSerialization.SERIALIZATION_MSGPACK Serializer(), WebSocketSerialization.serializationJson,
));
late Session session1; try { // connect to the router and start the wamp layer session1 = await client1 .connect( options: ClientConnectOptions( reconnectCount: 3, // Default is 3 reconnectTime: const Duration( milliseconds: 200) // default is null, so immediately // you may add ping pong options here as well )) .first;
} on Abort catch (abort) { // if the serve does not allow this client to receive a session // the server will cancel the initializing process with an abort print(abort.message!.message); } runApp(const MyApp()); }