简体   繁体   中英

nodeJS chat app created. How to run

I have created nodeJS io.socket chat app using the link here - http://cestfait.ch/content/chat-webapp-nodejs

I am able to run it on my laptop. I did not find any help on google how to connect to nodeJS app from other machines. I have another laptop which I have connected through wifi.

Now I really want to know how can I connect another user from another laptop to the nodeJS server running on my first laptop.

I will be very grateful for your help. Any help in broader sense will also be ok.

EDIT 1: When I am trying Brandon's method, I am getting following error. Not sure what is wrong. I have to run the file client.html directly in the browser. Running http://192.168.43.244:8000/client.html throws the error.

C:\node>node server.js
   info  - socket.io started

C:\node\node_modules\socket.io\lib\manager.js:0
(function (exports, require, module, __filename, __dirname) { /*!
^
RangeError: Maximum call stack size exceeded

It's complicated.

If you don't have a static IP address (and you probably don't) that means every time you reconnect your computer to the internet, you are going to get a new IP address, so you'd have to update your code every time.

Also, there are issues with Firewalls, both on your dev machine and with (wifi) routers.

Best solution is to acquire a static IP. But its not cheap

First, make sure Socket.IO is connecting to the server serving the HTML. In client.html , change:

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

to

var socket = io.connect();

Leaving out the host/port will cause Socket.IO to connect to the same host and port serving the HTML.

Once you've done that, you can access the server from another computer by visiting http://1.2.3.4:8000 , where 1.2.3.4 is the IP address of the computer running the server. The connecting computer and the serving computer will need to be on the same network for this to work; if you want to (temporarily) connect with someone on a different network, you can use a tool like localtunnel .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM