Hi, I am trying to use socket.io with cross domains. For example, suppose the domains are: https://client.domain.com and https://server.domain.com . My client side code is as follows:
socket = io.connect("https://server.domain.com"); socket.on("connect", function () { console.log("socketio Connected to server!"); }); socket.emit("test", {"test":"test"});
And server side:
var fs = require('fs'); var https = require('https'); var express = require('express'); var socketIO = require('socket.io'); var app = express(); // Settings var serverOptions = { key: fs.readFileSync('privkey1.pem'), cert: fs.readFileSync('cert1.pem') }; var serverPort = 443; // Logic var server = https.createServer(serverOptions, app); var io = socketIO(server); io.on('connection', function(socket) { socket.on("test", function(data) { console.log(data); }); }); server.listen(serverPort, function() { console.log('server up and running at %s port', serverPort); });
Everything works, messages are sent back and forth. But some reasone socket.io continue to try polling and the wrong domain. Almost every second I see this request:
Request URL:https://client.domain.com/socket.io/?EIO=3&transport=polling&t=1452418594321-145 Request Method:GET Status Code:302 OK
Why does the .io socket do this and how can I disable it?
EDIT: more interestingly, if I comment on all the code that needs to be done with socket.io and leave it only in <script src="https://server.domain.com/socket.io/socket.io.js"></script> , it still continues to make these HTTP requests described earlier.
EDIT2: Not sure if this will make a difference, but in reality domains are not subdomains of the same domain. They are https://clientdomain.com and https://serverdomain.com .
source share