3

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.

Roham Shojaei
  • 31
  • 1
  • 3

1 Answers1

1

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();

itsundefined
  • 1,409
  • 2
  • 12
  • 32
  • Thanks, I did it the error is gone but in inspect network tab when socket tried to connect it redirects my domain home page with this headers: ------ Request URL:http://www.example.com/ Request Method:GET Status Code:200 OK Remote Address:209.124.66.15:80 Referrer Policy:no-referrer-when-downgrade ----- it reapeats with every connection – Roham Shojaei Aug 27 '17 at 11:47
  • It seems your website is using HTTPS but you are using websockets without encryption. – itsundefined Aug 27 '17 at 11:49
  • I don't have SSL – Roham Shojaei Aug 27 '17 at 11:50
  • Sadly no idea then. Google around or edit your question here. – itsundefined Aug 27 '17 at 11:52
  • And also still dosn't work with var socket = io('http://example.com:52437', {secure:true}); – Roham Shojaei Aug 27 '17 at 11:53
  • This is a browser specific issue. It believes that your site is using HTTPS or some kind of encryption but when opening the socket.io connection, no encryption is used and brags about it. Other browsers don't have this error. Sadly this has never happened to me and I don't know what else can cause this. Must wait for more answers. You should edit your title or open a new question since you fixed the problem about no connection at all. – itsundefined Aug 27 '17 at 11:56
  • Thanks, the problem at the first place was net::ERR_CONNECTION_TIMED_OUT and now it's not changed! – Roham Shojaei Aug 27 '17 at 12:09