Hei, i am trying to use socket.io with cross domains. For example lets say domains are: https://client.domain.com and https://server.domain.com. My client side code looks like this:
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 get sent back and forth. But some reasone socket.io keeps trying to use polling and on wrong domain. Almost every second i see these request:
Request URL:https://client.domain.com/socket.io/?EIO=3&transport=polling&t=1452418594321-145
Request Method:GET
Status Code:302 OK
Why is socket.io doing that and how can i turn this off?
EDIT: whats more interesting is that if i comment out all the code to do with socket.io and only leave in the <script src="https://server.domain.com/socket.io/socket.io.js"></script>
it still keeps making these HTTP requests described earlier.
EDIT2: Not sure if this is going to make any difference but in reality the domains are not subdomains of one domain. They are https://clientdomain.com
and https://serverdomain.com
.