Use for Dart
WAMP v2 Client and Router for Dart.
Installation
To install xconn
, use the following command:
With Dart
With Flutter
Client
Creating a client:
import "package:xconn/xconn.dart";
void main() async {
var session = connectAnonymous("ws://localhost:8080/ws", "realm1");
}
Once the session is established, you can perform WAMP actions. Below are examples of all 4 WAMP operations:
Subscribe to a topic
void exampleSubscribe(Session session) async {
var subscription = await session.subscribe("io.xconn.example", eventHandler);
print("Subscribed to topic io.xconn.example");
}
void eventHandler(Event event) {
print("Received Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}");
}
Publish to a topic
void examplePublish(Session session) async {
await session.publish("io.xconn.example", args: ["Hello World!", 100], kwargs: {"xconn": "dart"});
print("Published to topic io.xconn.example");
}
Register a procedure
void exampleRegister(Session session) async {
var registration = await session.register("io.xconn.echo", invocationHandler);
print("Registered procedure io.xconn.echo");
}
Result invocationHandler(Invocation invocation) {
return Result(args: invocation.args, kwargs: invocation.kwargs, details: invocation.details);
}
Call a procedure
void exampleCall(Session session) async {
var result = await session.call("io.xconn.echo", args: ["Hello World!"], kwargs: {"number": 100});
print("Call result: args=${result.args}, kwargs=${result.kwargs}, details=${result.details}");
}
Authentication
Authentication is straightforward. Simply create the object of the desired authenticator and pass it to the Client.
Ticket Auth
void main() async {
var session = connectTicket("ws://localhost:8080/ws", "realm1", "authid", "ticket");
}
Challenge Response Auth
void main() async {
var session = connectCRA("ws://localhost:8080/ws", "realm1", "authid", "secret");
}
Cryptosign Auth
void main() async {
var session = connectCryptosign("ws://localhost:8080/ws", "realm1", "authid", "d850fff4ff199875c01d3e652e7205309dba2f053ae813c3d277609150adff13");
}
For more detailed examples or usage, refer to the examples folder of the project.
Server
Setting up a basic server is straightforward:
import 'package:xconn/xconn.dart';
void main() async {
var router = Router()
..addRealm('realm1');
var server = Server(router);
await server.start('localhost', 8080);
}
For more advanced usage, such as integrating an authenticator, refer to the sample tool available in the bin folder of the project.