Chatting with socket.io just to prove the concept still works fine, but I can't get the emit callback to work on the client side. I need to miss something stupid, but the documentation is not a killer at the moment. The server captures the getSomeData event just fine, no errors anywhere.
From what I could say in the source of client socket.io, it checks to see if the last argument for emitting is a function and always uses it as a callback, but debugging any deeper than that was problematic for me.
I feel like I am missing a basic concept. Is this not what this.send(..) should do? I could only find 1 use in the sample applications, and not one of them where client-side code was available for this event.
Update: just to be clear, I actually intentionally emit the client side of the event. The purpose of this was to find out if socket.io can be used so that clients can retrieve data on demand in addition to receiving clicks.
Server:
var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.on("getSomeData", function() { this.send({data: "some random data"}); }); });
client: (console.log never happens)
<script type="text/javascript" src="http://localhost/socket.io/socket.io.js"></script> <script type="text/javascript"> var socket = io.connect('http://localhost'); socket.emit("getSomeData", function(data) { console.log(data); }); </script>
source share