0

我有这个 tls 客户端,在这个客户端内部我有一个服务器,它为从 ServerX 到 PHP 客户端的数据提供服务……太疯狂了,是吗?好的..一切都很好,非常快...但是我想在 ServerX 响应它时回答 PHP 的问题,但它不是同步。请阅读:

var ServerX = tls.connect(port,host,options,function() {
    console.log(' Logging to ServerX...');
    var phpServer = dnode({
        fromPHP: function (variables,correlationalCallbackId,callBackToPHP) { // Shared PHP/NODE function
            othermodule.serialize(variable, function(buffer){ 
    HOW TO MAKE THIS-> global.phpCallBacks[correlationalCallbackId] = callBackToPHP; //I want to stores CallbackToPHP to use later when response from ServerX arrive
                ServerX.write(buffer,function(){ // write buffer to ServerX
                    //console.log("buffer sent");
                                    //callBackToPHP("Response from ServerX");//<--It works, but response dont exists
                });
                global.phpCallBacks[correlationalId]('Hi PHP! :)'); //Dont work even here
            });
        }// toNode END
    });
    //Starts DNODE server to integrate with PHP scripts
    phpServer.listen(PHPServerPort);    

});

我想在收到具有相关 ID 的特定响应时调用 callbackToPHP

ServerX.on('data', function(data) {
    othemodule.decode(data,function(message){ // message is an object with messageCorrelationId and other informations
        if(global.phpCallBacks[message.messageCorrelationId]) {
HOW TO MAKE IT WORK HERE-> global.phpCallBacks[message.messageCorrelationId](message.informations); // never fire :((
        }
    });
});

希望它得到很好的解释......当被数百万个范围嵌套时,如何使回调函数在全局范围内工作?!?!?

4

0 回答 0