[英]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 我使用此处的链接创建了nodeJS io.socket聊天应用程序 - 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.
我没有在谷歌上找到任何帮助如何从其他机器连接到nodeJS应用程序。 I have another laptop which I have connected through wifi.
我有另一台笔记本电脑,我通过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. 现在我真的想知道如何将另一台用户的另一台用户连接到我第一台笔记本电脑上运行的nodeJS服务器。
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. 编辑1:当我尝试布兰登的方法时,我得到了跟随错误。 Not sure what is wrong.
不确定有什么问题。 I have to run the file
client.html
directly in the browser. 我必须直接在浏览器中运行文件
client.html
。 Running http://192.168.43.244:8000/client.html
throws the error. 运行
http://192.168.43.244:8000/client.html
会抛出错误。
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. 如果您没有静态IP地址(并且您可能没有),这意味着每次将计算机重新连接到互联网时,您将获得一个新的IP地址,因此您必须每次更新代码时间。
Also, there are issues with Firewalls, both on your dev machine and with (wifi) routers. 此外,在您的开发机器和(wifi)路由器上都存在防火墙问题。
Best solution is to acquire a static IP. 最佳解决方案是获取静态IP。 But its not cheap
但它并不便宜
First, make sure Socket.IO is connecting to the server serving the HTML. 首先,确保Socket.IO连接到服务于HTML的服务器。 In
client.html
, change: 在
client.html
,更改:
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. 省略主机/端口将导致Socket.IO连接到为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. 完成后,您可以访问
http://1.2.3.4:8000
从另一台计算机访问服务器,其中1.2.3.4
是运行服务器的计算机的IP地址。 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 .
如果您想(临时)与不同网络上的某个人联系,您可以使用localtunnel之类的工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.