开发者

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);
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜