日期:2014-05-16  浏览次数:20470 次

JavaScript 通讯框架 NowJS

NowJS 是一个实现了 JavaScript 服务器端进行通讯的框架,基于 Node.js 开发。

示例代码:

服务器端:

<script src="/nowjs/now.js"></script>
var everyone = require("now").initialize(httpServer);

everyone.now.getServerInfo = function(callback){
  db.doQuery(callback);
  return "done!"
}
everyone.now.distributeMessage = function(message){
  everyone.now.receiveMessage(this.now.name, message);
};

客户端代码:

<script type="text/javascript" src="http://localhost:8080/nowjs/now.js"></script>

<script type="text/javascript">
  now.ready(function(){
    // alerts "Hello World!"
    alert(now.msg);
  });
</script>