简体   繁体   English

失败:连接建立时出错:.net::ERR_CONNECTION_REFUSED

[英]Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

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 '^]'.

CONNECTION_REFUSED is standard when the port is closed, but it could be rejected because SSL is failing authentication (one of a billion reasons).当端口关闭时 CONNECTION_REFUSED 是标准的,但它可能会被拒绝,因为 SSL 验证失败(十亿个原因之一)。 Did you configure SSL with Ratchet?您是否使用 Ratchet 配置了 SSL? (Apache is bypassed) Did you try without SSL in JavaScript? (绕过 Apache)您是否尝试过在 JavaScript 中不使用 SSL?

I don't think Ratchet has built-in support for SSL.我认为 Ratchet 没有内置对 SSL 的支持。 But even if it does you'll want to try the ws:// protocol first;但即使是这样,您也需要先尝试 ws:// 协议; it's a lot simpler, easier to debug, and closer to telnet.它更简单,更容易调试,更接近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).如果服务不支持 SSL(因为您明确请求 SSL),Chrome 或套接字服务也可能会生成 REFUSED 错误。

However the refused message is likely a server side problem, (usually port closed).然而,被拒绝的消息很可能是服务器端的问题(通常是端口关闭)。

Firstly, I would try a non-secure websocket connection.首先,我会尝试一个非安全的 websocket 连接。 So remove one of the s 's from the connection address:因此,从连接地址中删除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 8080 both in TCP_IN and TCP_OUT .您需要在TCP_INTCP_OUT打开端口8080

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

I had the same issue - the client script ran in a browser on Windows 10, the websocket server ran on WSL 2 (nodejs app using the WebSocketServer package ).我遇到了同样的问题 - 客户端脚本在 Windows 10 上的浏览​​器中运行,websocket 服务器在 WSL 2(使用WebSocketServer 包的nodejs 应用程序)上运行。

Only the localhost or the IPv6 localhost [::1] variant (to which the browser will eventually resolve when localhost is used) will actually correctly connect to WSL 2 and hence to the nodejs websocket server app.只有localhost或 IPv6 localhost [::1]变体(浏览器最终会在使用localhost时解析到该变体)才能真正正确连接到 WSL 2,从而连接到 nodejs websocket 服务器应用程序。 IPv4 127.0.0.1 localhost will not work in that case ( Connection refused ).在这种情况下 IPv4 127.0.0.1 localhost 将不起作用( Connection refused )。

You can check that yourself in browser (Chrome): When you request a websocket address, many implementation will respond with Upgrade Required .您可以在浏览器 (Chrome) 中自行检查:当您请求 websocket 地址时,许多实现将响应Upgrade Required

maybe you forgot to start websocket server, check it again, with configuration in my project, run:也许你忘了启动websocket服务器,再检查一遍,在我的项目中配置,运行:

php artisan websocket:init

You can use npm i y-websockets-server and then use the below command您可以使用npm i y-websockets-server然后使用以下命令

y-websockets-server --port 11000

and here in my case, the port No is 11000.在我的情况下,端口号是 11000。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chrome 扩展 WebSocket 连接到“ws://localhost:9090/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - chrome extension WebSocket connection to 'ws://localhost:9090/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接到“wss://ip:8080/”失败:连接建立错误:net::ERR_CONNECTION_REFUSED - WebSocket connection to 'wss://ip:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED WebSocket 连接失败:连接建立时出错:.net::ERR_CONNECTION_REFUSED - WebSocket connection failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED Websocket连接被拒绝。 WebSocket与&#39;ws://127.0.0.1:2000 /&#39;的连接失败:连接建立错误:net :: ERR_CONNECTION_REFUSED - Websocket connection refused. WebSocket connection to 'ws://127.0.0.1:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED 错误选项 net::ERR_CONNECTION_REFUSED - Error OPTIONS net::ERR_CONNECTION_REFUSED AxiosError:加载资源失败:net::ERR_CONNECTION_REFUSED - AxiosError : Failed to load resource: net::ERR_CONNECTION_REFUSED Webkit浏览器无法加载资源:net :: ERR_CONNECTION_REFUSED - Webkit Browsers Failed to load resource: net::ERR_CONNECTION_REFUSED 发出GET请求时出错“无法加载资源:net :: ERR_CONNECTION_REFUSED” - error when making GET request “Failed to load resource: net::ERR_CONNECTION_REFUSED” JQuery 网络::ERR_CONNECTION_REFUSED - JQuery net::ERR_CONNECTION_REFUSED 端口8888 net :: ERR_CONNECTION_REFUSED - port 8888 net::ERR_CONNECTION_REFUSED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM