2

I have developed a simple chat using socket.io on a vagrant environment and it works correctly.

When I try to run the chat on the production environment, the nodejs/socket.io server runs but the client doesn't even fire the connect event. The only thing I've modified is, in the client side:

var socket = io.connect('http://localhost:3000');

to:

var socket = io.connect('http://ip_address:3000');

This is the server code:

var app = require('http').createServer(handler);
var io = require('socket.io')(app);
app.listen(3000, function() {
    console.log('Server is running');
});
function handler(req, res) {
    res.writeHead(200);
    res.end('');
}

io.on('connection', function(socket) {
    socket.on('subscribe', function() {
        console.log('subscribe request has arrived');
        console.log(socket.id);
    });
});

1 Answer 1

2

If it worked locally and stopped working after deployment, it's probably a network issue - firewall, blocked port, linux enforcing or something of that sort.

To find the source, go to the host server and try connecting the port

telnet 127.0.0.1 3000 

Did you get 'Connection refused' error? if so which server is running the code? make sure firewall service is either off or with exceptions for port 3000. on linux check enforcing .

If the connection succeed, test the connection from your local pc

 telnet ip_address 3000 

If it fails than test access to external service (for example portquiz.net) This way you will know if the issue is with your local pc or network, or the remove server.

Sign up to request clarification or add additional context in comments.

2 Comments

The 3000 port was blocked by the firewall. Now it works perfectly..Thank you very much!
On my case I specified the listen address which restricted who could connect. Changing it to ''. Solved the connection refused issue. eventlet.wsgi.server(eventlet.listen(('', int(server_port))), app)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.