开发者

How do I pass data from the client-side to my nodejs server using socketio?

开发者 https://www.devze.com 2023-04-12 21:42 出处:网络
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 so

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

精彩评论

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

关注公众号