开发者

NodeJs and NowJs on EC2 lose connection

I have deployed NodeJS and NowJS to be a messaging server on EC2, when I logged on to EC2 and start with command "node server.js" it works fine. but if I start in the background and loggout out from EC2 with command "node server.js & > node.out"

Sometime Jetty (Webserver) can't connect o NowJs. I'm not sure why that happened, Am I missing something?

This is my code.


var http = require('http');
var httpServer = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
});

httpServer.listen(3000);

var nowjs = require("now");
var everyone = nowjs.initialize(httpServer);
everyone.now.distributeMessage = function(ids, message){
    everyone.now.receiveMessage(ids, message);
};

BTW I can still see http://localhost:3000/nowjs/now.j开发者_如何学JAVAs in firebug on EC2, but when I call everyone.now.distributeMessage. I got error saying that It's undefined. But when I logged on to EC2 and start the server again, it works fine.


with the command you provided your process is running in your user's ssh session. when you logout the session goes away. it could be as simple as using nohup.

try this:

nohup node server.js & > node.out
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜