Vote count:
0
I am currently doing a project to automatically spawn new servers dynamically when the current server is overloaded.I am using node.js for creating server.I have also calculated the number of requests using a variable.Is this procedure right? Or should i change my code?
I used a function to spawn a server with arguments server name and port number. but i am getting error in the port number which i have specified. The error is process.nextTick error. The error is on the port number in the function call.
I need a correct procedure to pass port number as arguments to the function.
i used the following coding:
var http=require('http');
var fs=require('fs');
var file=fs.readFileSync('file.html');
var reqno=1;
function spawnserver(servername,port)
{
servername=http.createServer(function(req,res){
res.writeHeader(200,{"Content-Type":"text/html"});
res.end(file);
});
servername.listen(port);
}
var server=http.createServer(function(req,res){
res.writeHeader(200,{"Content-Type":"text/html"});
res.end(file);
reqno++;
});
server.listen(3000);
if(reqno>200)
{
function spawnserver(server2,9615);
}
The error is: vishnu@vishnu-VirtualBox:~$ node server.js
/home/vishnu/server.js:21 function spawnserver(servername,9615); ^^^^
node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ SyntaxError: Unexpected number at Module._compile (module.js:429:25) at Object..js (module.js:459:10) at Module.load (module.js:348:32) at Function._load (module.js:308:12) at Array.0 (module.js:479:10) at EventEmitter._tickCallback (node.js:192:41)
can anyone help me out?
asked 29 secs ago
passing port number as parameter in node.js
Aucun commentaire:
Enregistrer un commentaire