【发布时间】:2012-07-13 19:59:05
【问题描述】:
我有一个简单的 nowjs 客户端代码:
$j(document).ready(function() {
window.now = nowInitialize('http://xxx.yyy:6564');
now.recvMsg = function(message){
$j("body").append("<br>" + message);
}
$j("#send-button").click(function(){
now.sendMsg("well done"); //## this work
});
now.sendMsg("aaaah"); //## this dont work
});
和服务器端代码:
var server = require('http').createServer(function(req, res){});
server.listen(6564);
var nowjs = require("now");
var everyone = nowjs.initialize(server);
everyone.now.sendMsg = function(message){
everyone.now.recvMsg(message);
};
并且调用 sendMsg(服务器端函数)在单击事件函数中起作用,但在就绪事件之外则不起作用。为什么?
我什至尝试过这样的事情:
setTimeout('now.sendMsg("aaaah")',1000);
还是不行。
【问题讨论】:
-
我不知道你的意思,但我设置了它:setTimeout('now.sendMsg("aaaah")',2000);并且工作 2 秒,但不能工作 1 秒。嗯,也许我一直循环到现在。sendMsg 存在
标签: javascript node.js nowjs-sockets