javascript - socket.io: multiple connects to same port -
we have client application multiple, independent frames. each frame should able connect separately node.js server on same port. each frame receive different messages.
xsp.addonload(function() { var channel= new messagechannel("system.sjef-bosman"); channel.on('company', function(thismessage) {if(thismessage.id=="dd3a") xsp.partialrefreshget("view:_id1:_id4:cccompanypanel", {});}); channel.on('contact', function(thismessage) {if(thismessage.id=="dd3e") xsp.partialrefreshget("view:_id1:_id4:cccontactpanel", {});}); })
xsp global object, dojo.
a messagechannel created every frame, using following code:
function messagechannel(channelname) { var _this= this; this.socket = io('http://' + window.location.hostname + ':3000'); this.callbacks= {}; this.on= function(evt, callback) { this.callbacks[evt]= callback; }; this.off= function(evt) { this.callbacks[evt]= undefined; // delete callbacks[evt]; } this.call= function(data) { if(data.cmd in this.callbacks) { var f= _this.callbacks[data.cmd]; (f)(data); } } this.isopen= function() { return this.socket.connected; } this.socket.on(channelname, function(msg) { console.log("channel " + channelname + ": " + msg); var data= json.parse(msg); _this.call(data); }); this.socket.on('connect', function() { console.log('connected', _this.socket.connected); }); console.log("connecting channel " + channelname); }
what happens when message comes in, first messagechannel triggered , not other(s).
is @ possible connect twice same port , both receive same messages? or how should go this??
thanks!
Comments
Post a Comment