Javascript ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34246333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js
提问by Jose Ricardo Citerio Alcala
Ciao, I'm implementing a webRTC many-to-many videoconferencing system, actually, I already did it, I am using socket.IO as signalling server, and everything goes super well, I am using EnterpriseDB Apache for serving my .html file on port (8081) and Node.js for serving socket.IO on port (3000), It is working like charm in localhost, no errors, My ISSUE is serving for external access with my public IP, I am testing with my friends and these browsing services: www.browserstack.com and www.browserling.com (trial versions).
Ciao,我正在实现一个 webRTC 多对多视频会议系统,实际上,我已经做到了,我使用 socket.IO 作为信令服务器,一切都非常顺利,我正在使用 EnterpriseDB Apache 为我的 .html 文件提供服务在端口 (8081) 和 Node.js 上为端口 (3000) 上的 socket.IO 提供服务,它在 localhost 中就像魅力一样工作,没有错误,我的问题是通过我的公共 IP 为外部访问服务,我正在和我的朋友一起测试,这些浏览服务:www.browserstack.com 和 www.browserling.com(试用版)。
with www.browserstack.com, everything is working fine with either mozilla 42 or chrome 47
with www.browserling.com, I got these errors
Firefox 41: ReferenceError: io is not defined
Chrome 45: Failed to load resource http://localhost:3000/socket.io/socket.io.jsnet::ERR_CONNECTION_REFUSED Uncaught ReferenceError: io is not defined
with my friends, I am having the same issues as www.browserling.com, but they are using the latest browser versions (Chrome 47 and Firefox 42) for connecting to my PC server.
使用 www.browserstack.com,使用 mozilla 42 或 chrome 47 一切正常
使用 www.browserling.com,我收到了这些错误
Firefox 41:ReferenceError:io 未定义
Chrome 45:无法加载资源 http://localhost:3000/socket.io/socket.io.jsnet::ERR_CONNECTION_REFUSED Uncaught ReferenceError: io is not defined
和我的朋友一起,我遇到了与 www.browserling.com 相同的问题,但他们使用最新的浏览器版本(Chrome 47 和 Firefox 42)连接到我的 PC 服务器。
I think this is not a browser version issue, The issue is on serving the socket.io.js file, finally, here is my code:
我认为这不是浏览器版本问题,问题在于提供 socket.io.js 文件,最后,这是我的代码:
It shows just the important things in order to solve this problem:
它仅显示了解决此问题的重要事项:
///NODE.JS DIRECTORY
////////////////////serverside.js
var port = 3000;
var io = require('socket.io').listen(port);
io.sockets.on('connection', function (socket){.........}
///APACHE DIRECTORY
////////////////////clientside.js
//Connect to signalling server
var socket = io.connect("http://localhost:3000");
////////////////////avq.html
<!DOCTYPE html>
<html lang="es">
<head><meta charset="UTF-8">
</head>
<body>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script src="js/clientside.js"></script>
</body>
</html>
this is my server URL if anyone wants to try: http://201.209.104.33:8081/webrtcexamples/avq.html
如果有人想尝试,这是我的服务器 URL:http: //201.209.104.33: 8081/webrtcexamples/avq.html
回答by jcaron
localhost
is a special host name that points to the same computer as the one requesting it. So anyone using a different computer than yours and trying to connect to localhost
will try to connect to its own computer, not yours. As the server is not running on their computer, they quite obviously get a "connection refused" error.
localhost
是一个特殊的主机名,它指向与请求它的计算机相同的计算机。因此,使用与您不同的计算机并尝试连接的任何人都localhost
将尝试连接到自己的计算机,而不是您的计算机。由于服务器没有在他们的计算机上运行,他们很明显会收到“连接被拒绝”错误。
You need to replace localhost
with a globally accessible address (domain name or IP address). This also implies that you need to have your router map your external IP address to your computer running the server for this port (otherwise they will connect to your router, not your server).
您需要替换localhost
为全局可访问的地址(域名或 IP 地址)。这也意味着您需要让路由器将您的外部 IP 地址映射到运行此端口服务器的计算机(否则它们将连接到您的路由器,而不是您的服务器)。
回答by Haring10
try io.connect("http://201.209.104.33:3000");
instead of io.connect("http://localhost:3000");
尝试io.connect("http://201.209.104.33:3000");
代替io.connect("http://localhost:3000");
EDIT
编辑
You need to run the socket on the server that it is being used. So if you run it on your PC, your friends pc will not see it, because when it connects to localhost
, it will try to connect to the localhost
of THEIR pc. Not yours.
您需要在正在使用它的服务器上运行套接字。所以如果你在你的电脑上运行它,你朋友的电脑将看不到它,因为当它连接到 时localhost
,它会尝试连接到localhost
他们的电脑。不是你的。
I had the same issue before. You need to run it off of the server so that everyone can connect to it.
我之前也遇到过同样的问题。您需要在服务器上运行它,以便每个人都可以连接到它。