【发布时间】:2015-02-19 22:56:22
【问题描述】:
我曾经使用 socket.io 发出如下回调:
客户:
mysocket.emit('helloword', 'helloword', function(param){
console.log(param);
});
服务器:
var server = require('http').Server(app);
var sserver = io(server);
sserver.on('connection', function(socket){
console.log('connection');
socket.on('helloword', function(message, callback){
console.log(message);
console.log(callback+'');
console.log('arguments', arguments);
callback('helloword');
})
});
server.listen(config.port);
我使用angular-socket-io 作为socket.io-client 的包装器。我的服务很简单:
'use strict';
angular.module('core').factory('mysocket', function(socketFactory){
return socketFactory();
});
服务器输出:
connection
helloword
function (){
// prevent double callbacks
if (sent) return;
var args = Array.prototype.slice.call(arguments);
debug('sending ack %j', args);
var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
self.packet({
id: id,
type: type,
data: args
});
}
arguments { '0': 'helloword', '1': [Function] }
我的客户端控制台:
我的问题:
- 为什么我的回调没有触发?
【问题讨论】:
标签: javascript angularjs node.js sockets callback