How do I pass data from the client-side to my nodejs server using socketio?
Usin开发者_JAVA百科g socketio on the client side and nodejs with socketio on the server side, how would I go about passing data from the client side to the server? Would I use an emit function with socketio on the client side?
Yes. Client side or server side you simply emit events and handle events.
client side:
var socket = io.connect('http://localhost');
socket.emit('my other event', { my: 'data' });
server side:
io.sockets.on('connection', function (socket) {
socket.on('my other event', function (data) {
console.log(data);
});
});
精彩评论