Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crossdomain - Handshake but "XMLHttpRequest cannot load" #1046

Closed
Mandragor opened this issue Oct 7, 2012 · 6 comments
Closed

Crossdomain - Handshake but "XMLHttpRequest cannot load" #1046

Mandragor opened this issue Oct 7, 2012 · 6 comments

Comments

@Mandragor
Copy link

I have exactly the same problem between my two servers, the handshake is made but I have the folllowing error.

XMLHttpRequest cannot load http://www.SERVER:8111/socket.io/1/?t=1349514190664. Origin http://CLIENTSERV.com is not allowed by Access-Control-Allow-Origin.

tryed the origin parameters and I've uploaded the socket.io.js file on the client server... can"t see why I have so much ifficulties to make that work since I have

info - socket.io started
debug - client authorized
info - handshake authorized KdzAXjXfzP3JfRoZUCMa

Any one can help me ? I'm getting desperate

@crickeys
Copy link
Contributor

crickeys commented Oct 7, 2012

Is your CPU at 100% for node? I noticed this happening as socket.io is using 100% or more of my cpu and then occasionally I get an xhr request that doesn't complete in time and then I see that error in my browser.

I tried extending some timeouts which seemed to help:

io.set('heartbeat interval', 45);
io.set('heartbeat timeout', 120);
io.set('polling duration', 20);
io.set('close timeout',120);

@Mandragor
Copy link
Author

crickeys Thanks for your comment but it didn't worked .... here are my codes :

server side :

var io = require('socket.io').listen(8888);

io.set('heartbeat interval', 45);
io.set('heartbeat timeout', 120);
io.set('polling duration', 20);
io.set('close timeout',120);

io.sockets.on('connection', function(socket){
socket.emit('server ready', {msg: 'hi'}) ;

socket.on('random event', function(data) {
    console.log('received');
})

});

Client Side :

<script src="socket.io.js"></script>

$(document).ready(function() {
var socket= io.connect('http://www.MYCLIENTSERVER:8888');

socket.on('server ready', function(data){ 
    console.log('server ready!'); 
});

socket.emit('random event', {hurr: 'durr'});

});

@mattcodez
Copy link

I just ran into what I think is the exact same issue and after a lot of code digging, I've found a work around. Long story short, when you tell Socket.io to listen on a port (i.e. not let it default to 80), a default HTTP request handler is created (line 69 of socket.io.js). This default handler automatically writes to and ends the request which prevents the Access-Control-Allow-Origin header from being written to the request by the Manager request handler. The solution I'm using for now is to dynamically remove this default handler in my own code (so not editing any Socket.io code here):

io = io.listen(8888);
io.server.removeListener('request', io.server.listeners('request')[0]);

This works for me. I still think there should be some sort of fix or added option around this though as I don't feel the above to necessarily be stable in the wake of future Socket.io code changes.

@duylam
Copy link

duylam commented Apr 18, 2013

mattcodez is right and his solution works so far :)

@sfarthin
Copy link

+1

@ilovett
Copy link

ilovett commented Jun 4, 2014

Thanks @mattcodez that was annoying.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants