skip to Main Content

I create app with nodejs socket io. It works clearly at localhost (port: 3000). But when i deploy it to my server in there i can run my app on 3000 port but client side throw timeout. How can i solve it?

var fs = require('fs');

var https = require('https');
var options = {
  key: fs.readFileSync('ssl.my-key.key'),
  cert: fs.readFileSync('ssl.my-cert.crt')
};
var server = https.createServer(options);
var io  = require('socket.io').listen(server);
var port = 3000;

const database = require('./Database');

io.on('connection', (socket) => {

  socket.on('message', async (msg) => {
    // I do some action here.
  });

  socket.on('disconnect', (msg) => {
    // some action in here too
  });

});

server.listen(port, () => {
  console.log('listening on *:' + port);
});

2

Answers


  1. It seems like your issue is with port forwarding.
    In order for your server to be publicly accessed, it needs to have all ports forwarded appropriately. Locally and on the router.

    Check this link to learn more about how to port forward on linux: https://linuxacademy.com/guide/11630-internal-port-forwarding-on-linux-using-the-firewall/

    And this to learn more about router port forwarding, but this will really depend on your router.

    https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/

    However, I don’t recommend you to take care of hosting on your own machine(s). I
    suggest you use Heroku, you can op in for their free servers, you don’t need to pay.

    More about heroku and NodeJS: https://linuxacademy.com/guide/11630-internal-port-forwarding-on-linux-using-the-firewall/

    Login or Signup to reply.
  2. let we debug your node js app.
    1) add some logs on database connection, http.createserver, also where you have to check if not success then catch exception

    2) you should have to open port on centOs before start your node js app

    3) you should have test you with domain name or ip address

    as per you comment you got connection timeout , you mean node js server trying to connect with port 3000 but node not able to connect and its throws error with connection timeout

    also send your sample code of your main index file so we can investigate your problen
    thanks.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search