我正在使用 node.js 和 socket.io 开发一个多人画布游戏,我的节点服务器在建立客户端握手后立即抛出大量相同的错误时遇到问题。
这是来自控制台的复制/粘贴:
info - handshake authorized GeDlfwyEdfEIJXGvoZjG
new player connected: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
22:3:26 - (onMovePlayer) Player not found: GeDlfwyEdfEIJXGvoZjG
你可以在这里查看完整的代码:http: //github.com/storrdev/delta-wing
基本上我遇到了一个问题,server.js(节点脚本)的节点控制台吐出“(OnMovePlayer)Player Not Found:CONNECTION ID ”,其中CONNECTION ID是连接的客户端的ID。
当服务器从客户端接收到“移动播放器”消息并且在存储在服务器上的播放器数组中找不到播放器的 ID 时,我编写了该错误消息以在调用函数 onMovePlayer() 时显示。
我无法理解的是,在客户端向服务器发出“移动播放器”消息之前,服务器甚至不应该调用 onMovePlayer() 函数,并且客户端不应该在之后发出“移动播放器”消息建立连接,并向服务器发出“新玩家”消息。
为什么会多次抛出此错误?socket.emits 是否乱序发送?我很混乱。
我知道这很复杂,所以我很感激我能得到的任何帮助或想法。老实说,我希望将情况输入出来可以帮助我弄清楚,但不幸的是它没有。