loading...

Can't connect to remote server running Socket.io

dmahely profile image Doaa Mahely ・1 min read

UPDATE:

It turns out the port 3000 on the remote server wasn't open. Thanks everyone for reading.

=========

Hello everyone.

I have a socket.io client that I connect to the socket.io server I'm running in my localhost using

const io = require('socket.io-client');
const chatSocket = io.connect('http://127.0.0.1:7000/');

Everything works well and I can send messages through the socket that are logged in the server.

This is the code I use on the server side:

let app = require("express")();
let http = require("http").Server(app);
let io = require("socket.io")(http);

io.on("connection", function() {
console.log("connected");
});

http.listen(port, function () {
  console.log("listening in port 3000");
});

The problem is that "connected" never logs when I run the same code on a remote server. Just the "listening in port 3000" part. I'm substituting the server's IP address and port in io.connect(). I even tried with the DNS name but it's still not connecting. I've checked the dependencies and they're the same as my local environment.

What could I be missing?

Posted on by:

dmahely profile

Doaa Mahely

@dmahely

Software engineer and full stack developer. She/her.

Discussion

markdown guide
 

Where are you setting your port variable on your server side? Also note that your front end lists the port number as 7000, but your comment on the server mentions 3000.

 

Hello Brandin. My bad, I'm connecting to port 7000 on my local which works, but connecting to port 3000 on the remote server. I'm starting to think port 3000 is closed or something.