Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  126] [ 3]  / answers: 1 / hits: 16660  / 11 Years ago, tue, april 9, 2013, 12:00:00

Can I connect to multiple resources on the same IP and port on the client side?



I have the following code-



var myIP = 192.168.1.1;
var myPort = 8080;

A = io.connect(myIP+':'+myPort,{resource: 'A/socket.io'});
B = io.connect(myIP+':'+myPort,{resource: 'B/socket.io'});

A.on('connect',console.log('A connected');
B.on('connect',console.log('B connected');

A.on('message',function(d){console.log('A: '+ d);}
B.on('message',function(d){console.log('B: '+ d);}


I am running node-http-proxy on myIP:myPort.
It is proxying connections on A and B to their respective socket-io servers.



If I run the above code on a single script, the browser ignores the second statement (It does not fires a request to resource B).



The on(message) callbacks for both A and B recieve the same data which actually belongs to A.



If I run the above code in two different html pages (A on one and B on other), they work fine and I get the data for both separately.


More From » socket.io

 Answers
2

Try this:



A = io.connect(myIP+':'+myPort, {resource: 'A/socket.io', 'force new connection': true});
B = io.connect(myIP+':'+myPort, {resource: 'B/socket.io', 'force new connection': true});


(Yes, I removed some of the quotes)


[#79023] Monday, April 8, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cody

Total Points: 679
Total Questions: 111
Total Answers: 111

Location: Czech Republic
Member since Thu, Aug 11, 2022
2 Years ago
;