socket.io net::ERR_CONNECTION_TIMED_OUT error

8k views Asked by At

I have a website with a real time chat it works on localhost without error but on server I get this error:

http://my.domain:52398/socket.io/?EIO=3&transport=polling&t=LuZMbMn net::ERR_CONNECTION_TIMED_OUT

i.create @ socket.io.min.js:2
i @ socket.io.min.js:2
o.request @ socket.io.min.js:2
o.doPoll @ socket.io.min.js:2
n.poll @ socket.io.min.js:2
n.doOpen @ socket.io.min.js:2
n.open @ socket.io.min.js:2
n.open @ socket.io.min.js:2
n @ socket.io.min.js:2
n @ socket.io.min.js:1
n.open.n.connect @ socket.io.min.js:1
(anonymous) @ socket.io.min.js:1

A part of server.js file content is:

var express = require("express"), http = require('http');
var app = express();
var server = http.createServer(app);
var port  = 52398;
var io = require('socket.io')(server);
server.listen(port, 'my.domain');

And client.js file connection part is:

var socket = io.connect('http://my.domain:52398');

I use shared hosting so they said I have to use a free port number between 49152 and 65535, Node.js is installed also npm is installed, Node version is 4.6.2, OS of server is Centos.

I searched a lot changed port, Changed domain name by server ip, Changed server connection codes and ... now I have no clue what is wrong help please Thanks.

1

There are 1 answers

7
itsundefined On

Change the fifth line of you server.js file to this:

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

After that since your express app and socket.io server is running on the same port you should change var socket = io.connect('http://my.domain:52398'); to var socket = io();