开发者

Can socket.io client connect to two different servers/ports?

开发者 https://www.devze.com 2023-03-23 10:32 出处:网络
Can socket.io client connect to two different ports on the same serve开发者_StackOverflow中文版r?

Can socket.io client connect to two different ports on the same serve开发者_StackOverflow中文版r?

Can socket.io client connect to two different server?


Sure:

var io1 = require('socket.io').listen(8001);

io1.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
});


var io2 = require('socket.io').listen(8002);

io2.sockets.on('connection', function (socket) {
  socket.emit('flash', { hello: 'world' });
});

Perhaps this is an interesting read: (from github)

// connect at the same host / port as your website
var socket = io.connect();

// different port or host
var socket = io.connect('http://url.com');

// secure
var socket = io.connect('https://localhost');


Can socket.io client connect to two different ports on the same server?

I assume both machines share same domain. I believe it can use long-polling(websockets, flashsockets, etc also work), even passing along cookie. But I still need to test this on Internet Explorer because that browser never does what I want...

Can socket.io client connect to two different server?

The big question is if those both machines are on different domains. If on same domain it will work just fine even passing along cookie(s). If they are on different domains then on some browser we fall-back to json-p transport(worst transport imaginable), but it will work. Unfortunately then the cookie is not passed along, because of same origin policy. Right now I am toying to get around this cookie restriction(hard problem)...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号