-
Notifications
You must be signed in to change notification settings - Fork 9
Home
joris hermans edited this page May 8, 2015
·
17 revisions
Dart Force is a Realtime web framework for Dart. We will make it easy for you to create realtime applications with it in Dart, like a chat, interactive dashboard, multiplayer games, ...
First of all you need a server to handle incoming messages and dispatch or handle this messages correctly.
import "package:force/force_serverside.dart";
ForceServer fs = new ForceServer();
main() {
fs.server.use("/", (req, model) => "dartforcetodo");
fs.start().then((_) {
fs.on("add", (vme, sender) {
fs.send("update", vme.json);
});
});
}
The client can listen to messages:
ForceClient fc;
void main() {
fc = new ForceClient();
fc.connect();
fc.onConnected.listen((e) {
fc.on("update", (fme, sender) {
querySelector("#list").appendHtml("<div>${fme.json["todo"]}</div>");
});
});
}
You can also send messages:
InputElement input = querySelector("#input");
var data = {"todo": input.value};
fc.send("add", data);
It is a little bit inspired by socket.io for the communication flow.