javascript - How to determine if variables from sockets match -
i have node.js server , im using socket.io communicate between 2 html pages.the 2 html pages send data across socket, each page has entity associated e.g host entity: 'host'
, responder vice versa.they both have name associated them same keep them 'paired' session e.g name: 'test'
.
when server accepts these connections have trouble finding out if there set. have is:
socket.on('hostresponderstatus', function(msg) { if(msg.status == 'connecting') { if(msg.entity == 'host') { namehost = msg.name; //grab name associated host socket.emit('staringgl', {status: 'starting', name: namehost}); //send socket stating gl starting } if(msg.entity == 'responder') { nameresponder = msg.name; //grab name associated responder socket.emit('staringgl', {status: 'starting', name: nameresponder}); //send socket stating gl starting } if(msg.name == namehost && msg.name == nameresponder) // if names same start child service { console.log("host name: "+namehost); console.log("host name: "+nameresponder); var child_info = child.fork(__dirname + '/child_proccess/child'); child_info.send({name: namehost}); } } });
but dont think ever reaches last if statement because 'host' , 'responder' both go there own if clauses , when have finished socket never accessed again. tried putting if clause main body of app.js this:
if(namehost == nameresponder) { var child_info = child.fork(__dirname + '/child_proccess/child'); child_info.send({name: namehost}); }
but fire when node started due both being null therefore equal. there better way check see if host , responder ready?
sorry tell that, code logic kinda messed up.
msg.entity
should have value "host" or "responder", variables namehost
, nameresponder
never same, because both being set inside different if conditions.
and if trying set namehost
, nameresponder
outside of if conditions, both same, because being assigned same object property msg.name
.
you need walk through logic again.
Comments
Post a Comment