socket.io-poco
socket.io-poco copied to clipboard
Socket.io send/emit with Callback
Hi,
first of all: Wonderful Socket.IO framework :)
But I still have a small request, I wonder how to realize the best, maybe it's on your agenda, or you have other ideas how to solve this (if technically not possible):
referring http://socket.io/#how-to-use there is something called callbacks (definable within a send or emit):
Sending and getting data (acknowledgements). Sometimes, you might want to get a callback when the client confirmed the message reception. To do this, simply pass a function as the last parameter of `.send` or `.emit`. What's more, when you use `.emit`, the acknowledgement is done by you, which means you can also pass data along: SERVERvar io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.on('ferret', function (name, fn) { fn('woot'); }); });
CLIENT
var socket = io.connect(); // TIP: .connect with no args does auto-discovery socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too! socket.emit('ferret', 'tobi', function (data) { console.log(data); // data will be 'woot' }); });
Is this somehow possible?
Kind regards BlackHornet
Is there anyone have answer for this ? the Event call back is not working when using it like below. SIOClient *sio = SIOClient::connect("http://192.168.1.231:3001"); TestTarget *target = new TestTarget();
sio->on("connect", target, callback(&TestTarget::ontestevent)); sio->on("testevent", target, callback(&TestTarget::ontestevent)); sio->emit("testevent","[{"username":"demo","password":"demo"}]");
Please how can I receive callback response from the server ?