javascript - socket.on not working for things I write? Help? It only works for disconnect. -
client:
var socket = io.connect(); socket.on('some stuff', function(){ console.log("please please work."); });
server:
var io = require('socket.io').listen(app); io.sockets.on('connection', function(socket){ console.log("yay, tab opened!"); socket.on('disconnect', function(){ console.log("aww, tab closed. "); }); socket.on('some stuff', function(){ console.log("did work? idk."); }); });
app server irrelevant. when run it, part works tab open tab closed part. when open localhost , go on there, says "yay tab opened" in windows console. (and when open more tabs, says message every tab open). when close tabs, says aww tab closed message every tab close.
but when trying add own function, doesn't care log in. realize i'm not doing function yet, need later on. want know why it's not logging it. disconnect works, "some stuff" doesn't work. why not?
if want client side send message have call emit
:
// client socket.emit('some stuff', {my:data}); // server socket.on("connection", function() { ... socket.on("some stuff",function(data){ console.log(data) ); });
the process can reversed of course can send data server client own function
Comments
Post a Comment