Opening of the previous thread throws an exception in the vibenews server, so I'll start a new one.
After playing with websockets, I wrote something very simple that resembles Socket.IO API:
auto io = new IoSocketManager;
auto router = new UrlRouter;
router.get("/socketio", &io.handleRequest); // endpoint for connection
// connection handle
io.onConnection( (socket) {
// message handler, data is Json
socket.onMessage( (data) {
// send message
socket.send(Json(["message" : Json("success")]));
// broadcast message to all sockets except this one
socket.broadcast(data);
});
});
And Javascript:
var socket = IoSocket.connect("/socketio");
socket.on("connect", function() {
socket.send({"message": "hello"});
});
socket.on("message", function(data) {
console.log(data.message);
});
All messages are encoded in Json for convenience. There's more to be added: reconnect on connection lost, connection timeouts, heartbeats(do you relly need them with Websockets?). I actually thought of implementing Socket.IO protocol, but that seemed too heavyweight and geared towards supporting multiple transports, so I decided to concentrate on Websockets for now. The code is at github. There is a test app as well.