Node.js, socket-io based one to one chat engine working fine on LOCAL but not working when running on different laptops using ngrok

回眸只為那壹抹淺笑 提交于 2021-02-11 16:39:29

问题


I am working on a chat server and it's working fine on local but whenever I try to run the project using ngrok then me and my friend are unable to chat.

var socket = io('http://localhost:7777', {
    query: {
        username: '<%= user %>'
      }
  });

Can anyone guide me how to make this public? Because the IP address changes everytime when connected to internet.

and

var app = express();

const chatServer = require('http').createServer(app);

chatServer.listen(7777);

I'm working in node.js for the first time


回答1:


If your server and client do work locally, as you mention, you have some additional challenges when running the server and client on different machines over the internet:

  • Your client needs to know the server external IP address. So you need some way to make it configurable on the client, for example using command line arguments.
  • If the local IP address of your server changes, you need to configure it to use a static IP address instead of using DHCP.
  • You probably need to setup port forwarding on your internet router at the server side. You need to tell your router to forward all traffic on port 7777 to your server.
  • You might need to configure your firewall to allow traffic on port 7777.
  • Your ISP can and will change your external IP address occasionally. Not much you can do about that. That's why servers on the internet are usually accessed using their (domain) name, which is static.


来源:https://stackoverflow.com/questions/60301083/node-js-socket-io-based-one-to-one-chat-engine-working-fine-on-local-but-not-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!