简体   繁体   English

未执行nodejs socket.io发出

[英]nodejs socket.io emit is not executed

I've got the problem that the second emit() in the following code (I have picked the important part if there is more needed just ask), which is sending a "stateChange"-Event, seems not to be executed. 我有一个问题,下面的代码中的第二个send()(如果有更多需要,我选择了重要的部分,只是问一下),它正在发送“ stateChange” -Event,似乎没有执行。 The "ID"-Event is received by the Server. 服务器接收到“ ID”事件。

this.socket = io.connect('...');
this.socket.emit("ID", {canvasID: this.ID});

this.socket.on(PLACE_BUBBLE, function(data){
    var node = uCanvas.placeBubble(data.x1, data.y1);
    this.socket.emit("stateChange",
        {action : PLACE_BUBBLE, canvasID : this.ID, nodeID : node.nodeID, x : node.x, y : node.y});
});

The server is looking like this: 服务器看起来像这样:

socketio.sockets.on("connection", function(socket){
    socket.on("ID", function(data){
       ...
    });
    socket.on("stateChange", function(data){
       ...
    });
});

placeBubble() is executed but there is simply no information send back to the server. placeBubble()已执行,但是根本没有信息发送回服务器。

/solved: Problem was "this" in this.socket.emit which should be uCanvas.socket.emit(). /解决:问题是this.socket.emit中的“ this”,应该是uCanvas.socket.emit()。 This was the object holding the socket. 这是持有插座的对象。

Solved: Problem was "this" in this.socket.emit which should be uCanvas.socket.emit(). 解决:问题是this.socket.emit中的“ this”,它应该是uCanvas.socket.emit()。 This was the object holding the socket. 这是持有插座的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM