Sending messages client->server->client on socket.io on node.js

后端 未结 2 1006
温柔的废话
温柔的废话 2020-12-30 10:29

I\'m using NodeJS+Socket.IO for simple web game. It works. Why?

Here\'s my server.js

var app = require(\'express\').createServer();
var          


        
2条回答
  •  时光说笑
    2020-12-30 11:00

    Server side

    socket.on('updatePlayer', function(updatePlayer){
      console.log("Someone just moved on the map!")
      updatePlayer() // will trigger the client side function
    });
    

    Client side

    socket.emit('updatePlayer', function(){
      console.log('testing');
    })
    

提交回复
热议问题