I'm a newbie in Node.js and I tried to node app.js to hold client but it gives me an error with this message below,
events.js:141
throw er; // Unhandled 'error' event
^
ReplyError: Ready check failed: ERR max number of clients reached
at parseError (/opt/smarthome/node_modules/redis-parser/lib/parser.js:181:12)
at parseType (/opt/smarthome/node_modules/redis-parser/lib/parser.js:291:14)
It worked well last week but after I disconnect and back to it, it gives me an error like above...
Also, here is my Node.js code
io.sockets.addListener('connection', function(socket){
console.log("connceted : " + socket.id);
var subscriber = redis.createClient(6379, 'localhost');
subscriber.psubscribe("*");
subscriber.on("pmessage", function(pattern, channel, message) {
//console.log(message);
socket.emit(channel, message);
});
socket.on('disconnect', function () {
console.log("disconnceted : " + socket.id);
subscriber.quit();
});
socket.on('close', function() {
console.log("close");
subscriber.quit();
});
});
server.listen(3000);
// Scheduler - DashBoard Update every 5 minutes
var testInterval = setInterval(function(){
channelCheck = "" ;
},300000);
// Reading JSON data of Dashboard
var front = fs_Dash.readFileSync('./dashboard_json/front.json', 'utf8');
var jsonContents = fs_Dash.readFileSync('./dashboard_json/jsoncontent.json', 'utf8');
var behind = fs_Dash.readFileSync('./dashboard_json/behind.json', 'utf8');
// Starting subscribe
subscriber.on("pmessage", function(pattern, channel, message) {
// Reading subscribe data
var s_data = JSON.parse(message);
var node_id = JSON.stringify(s_data.node_info[0].id).replace(/\"/g, "");
channel = channel.toUpperCase();
// Creating Channels data
openfile = fs_Dash.open('./sensor/'+channel+'.txt', 'a', function(err, fd) {
fs_Dash.close(fd);
});
// Reading Channels data
fs_Dash.readFile('./sensor/'+channel+'.txt', 'utf8', function(err, data) {
// Checking sensors list
sensor_list=JSON.stringify(data);
if(sensor_list == null) sensor_list = "";
sensors = sensor_list.replace(/\\n/g," ").replace(/\:/g, "").replace(/\"/g,"").split(' ');
alljson = front.replace('EXTITLE',channel);
for (var i = 0 ; i < sensors.length ; i++){
alljson += jsonContents.replace(/SENSORS/gi,channel+"_"+sensors[i].replace(/\"/g,""));
if(i >= sensors.length -2){
break;
}
alljson += ',';
}
// Updating Dashboard version
alljson += behind.replace('XXX', schemaVersion).replace('VVV', version);
version += 1;
schemaVersion += 1;
// Setting Request options
options = {
url: 'my private url',
headers: {
'Authorization' : "Basic " + new Buffer('hi' + ":" + 'hi').toString('base64'),
'Content-Type' : 'application/json',
'Accept' : 'application/json'
},
body: alljson
};
// Discovering a NEW channel => Updating Dashboard
if(JSON.stringify(channelCheck).search(channel) == -1){
request_Dash.post(options, function(err, res, body) {
console.log("renew dashboard");
});
channelCheck += channel+',';
}
// Discovering a NEW sensor => Updating Dashboard, Writing Sensor Data
if ((sensor_list).search(node_id)==-1){
// Sending post Dashboard generating message
request_Dash.post(options, function(err, res, body) {
console.log('status code : ' + res);
console.log("renew dashboard");
});
// Writing Channels and Sensor data
fs_Dash.appendFile('./sensor/'+channel+'.txt', node_id+'\n', function(err) {
if(err) throw err;
// console.log('File write completed');
});
}
});
//fs_Dash.close();
});
subscriber.psubscribe('*');
What's wrong with this..??
Does anybody have a solution for this..??
Thanks in advance.
via paulc1111
No comments:
Post a Comment