Javascript 失败:连接建立错误:net::ERR_CONNECTION_REFUSED
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28799792/
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
Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
提问by dasdasd
I try to connect with socket to my server. My server is running server socket with Rachet on port 8080. I try to run this code:
我尝试使用套接字连接到我的服务器。我的服务器在端口 8080 上运行带有 Rachet 的服务器套接字。我尝试运行以下代码:
<script>
try{
conn = new WebSocket('wss://localhost:8080');
conn.onclose = function (e)
{
//checkUser();
}
conn.onopen = function(e)
{
console.log("test");
};
}catch (error)
{
console.log(error);
}
</script>
But I get this error:
但我收到此错误:
WebSocket connection to 'wss://localhost:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
When I try to connect from my linux shell I get this:
当我尝试从我的 linux shell 连接时,我得到了这个:
root@(none):~# telnet localhost 8080
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
回答by btraas
CONNECTION_REFUSED is standard when the port is closed, but it could be rejected because SSL is failing authentication (one of a billion reasons). Did you configure SSL with Ratchet? (Apache is bypassed) Did you try without SSL in JavaScript?
当端口关闭时 CONNECTION_REFUSED 是标准的,但它可能会被拒绝,因为 SSL 验证失败(十亿个原因之一)。您是否使用 Ratchet 配置了 SSL?(绕过 Apache)您是否尝试过在 JavaScript 中不使用 SSL?
I don't think Ratchet has built-in support for SSL. But even if it does you'll want to try the ws:// protocol first; it's a lot simpler, easier to debug, and closer to telnet. Chrome or the socket service may also be generating the REFUSED error if the service doesn't support SSL (because you explicitly requested SSL).
我认为 Ratchet 没有内置对 SSL 的支持。但即使是这样,您也需要先尝试 ws:// 协议;它更简单,更容易调试,更接近telnet。如果服务不支持 SSL(因为您明确请求 SSL),Chrome 或套接字服务也可能会生成 REFUSED 错误。
However the refused message is likely a server side problem, (usually port closed).
然而,被拒绝的消息很可能是服务器端的问题(通常是端口关闭)。
回答by Nate
Firstly, I would try a non-secure websocket connection. So remove one of the s's from the connection address:
首先,我会尝试一个非安全的 websocket 连接。因此,s从连接地址中删除's之一:
conn = new WebSocket('ws://localhost:8080');
If that doesn't work, then the next thing I would check is your server's firewall settings. You need to open port 8080both in TCP_INand TCP_OUT.
如果这不起作用,那么接下来我要检查的是您服务器的防火墙设置。您需要8080在TCP_IN和 中打开端口TCP_OUT。
回答by Anton Lyhin
In my case the answer is pretty simple. Please check carefully the hardcoded url port: it is 8080. For some reason the value has changed to: for example 3030.
就我而言,答案很简单。请仔细检查硬编码的 url 端口:它是 8080。由于某些原因,该值已更改为:例如 3030。
Just refresh the port in your ajax url string to the appropriate one.
只需将 ajax url 字符串中的端口刷新为适当的端口。
conn = new WebSocket('ws://localhost:3030'); //should solve the issue

