Tag: crossbar

AutobahnJS:远程调用asynchronous函数

我试图通过WAMP拨打一个远程function。 但是如果它有asynchronous行为,我不知道如何编写被调用的函数。 在我看到的每个例子中,远程函数都返回结果。 如何以asynchronous的方式来完成,我通常会使用callback? 例子:这是一个函数的注册,它将asynchronous获取文件的内容。 session.register('com.example.getFileContents', getFileContents).then( function (reg) { console.log("procedure getFileContents() registered"); }, function (err) { console.log("failed to register procedure: " + err); } ); 以下是我将如何远程调用该function。 session.call('com.example.getFileContents', ["someFile.txt"]).then( function (res) { console.log("File Contents:", res); }, function (err) { console.log("Error getting file contents:", err); } ); 但是这是注册的实际function。 function getFileContents(file) { fs.readFile(file, 'utf8', function(err, data) { […]

Autobahn.JS掉线

我有一个Crossbar.js实现,在客户端(网站)和服务器(Node.js)之间通过Crossbar websocket服务器发送数据。 双方都使用Autobahn.JS连接到Crossbar服务器。 连接工作正常,但似乎客户端和服务器断断续续,随机时刻重新连接。 这大约每两分钟发生一次。 我也看到,双方的连接并没有同时发生。 这让我觉得问题在于我在双方使用的Autobahn实现(对于客户端和服务器来说大致相同)。 下面是我用来从Node.js连接到Crossbar服务器的方法。 浏览器的版本几乎完全相同。 我只改变了订阅,并改变了const并letvariablesvar 。 start(connectionConfig) { const self = this; self.host = connectionConfig.host; self.realm = connectionConfig.realm; self.channelPrefix = connectionConfig.channelPrefix; try { // Start an Autobahn websocket connection self.connection = new autobahn.Connection({"url": self.host, "realm": self.realm}); self.connection.onopen = function(session) { // Save session in class self.session = session; // Listen […]