WebSocket 连接到“ws://mydomain.com:8084/?peer_id=123"失败:连接建立错误:net::ERR_CONNECTION_TIMED_OUT [英] WebSocket connection to 'ws://mydomain.com:8084/?peer_id=123' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

查看:123
本文介绍了WebSocket 连接到“ws://mydomain.com:8084/?peer_id=123"失败:连接建立错误:net::ERR_CONNECTION_TIMED_OUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var ws = new WebSocket('ws://' + server); //server is mydomain.com:8084?peer_id=123
            console.log('ws://' + server);

            //var self = this;
            ws.onopen = function () {
                console.log("Opening a connection...");
            };
            ws.onclose = function (evt) {

                is_connected = false;
                console.log("Could not listen to the server. The connection is closing");
            };

            ws.onerror = function (evt) {
                console.log("ERR: " + evt.data);
            };

以上是从客户端连接socket服务器的一段代码.

Above is the piece of code to connect the socket server from client.

在服务器上,我使用 PHP WebSocket 来设置在后台运行的套接字服务器>

On server, I am using the PHP WebSocket to setup the socket server that is running on the background

$server = IoServer::factory(
            new HttpServer(
                new WsServer(
                    new RatchetGlobalServer()
                )
            ),
            8084
        );

        $server->run();

首先,它在我的本地主机上运行良好,我已将它部署到我的主机上,它也可以运行.但是,当我切换到另一个 ISP 时它不起作用,onOpen 事件不会触发,它抛出错误并最终关闭.

First, it works well on my localhost, I have deployed it to my host, it also works. However, it does not work when I switch to another ISP, The onOpen event does not fire, it threw the error and come to onclose eventually.

在我的国家,有四大 ISP 提供商:A、B、C、D

In my country, there are four big ISP providers: A,B,C,D

我尝试使用来自其他一些 ISP(B、C、D)的其他互联网线路,它完全不起作用,但它可以在我的家庭互联网线路(来自 ISP A)上工作.我必须强调,服务器已经位于专用服务器上,不再位于我的本地主机上.我的同事可以访问我的网站并看到它运行良好(他们与我使用相同的网络和路由器)

I tried to use other internet lines from some other ISPs (B,C,D), it totally does not work, but it does work on my home internet line (from ISP A). I have to emphasize that the server is located on the dedicated server already, it no longer to be on my localhost. My colleagues can access to my site and see it works fine (they are using same the network and router with me)

是不是我的路由器上的配置只能使事情起作用?我不知道发生了什么.我试图找出它好几天.

Is it something about configuration on my router only make the thing work? I have no idea what happening. I tried to find it out for days.

关闭事件带有代码 1006,原因为空:

The close event came with the code 1006 with empty reason:

CloseEvent {}
bubbles: false
cancelBubble: false
cancelable: false
code: 1006
currentTarget: WebSocketdefaultPrevented: false
eventPhase: 0
path: Array[0]
reason: ""returnValue: true
srcElement: WebSockettarget: WebSockettimeStamp: 1438951964550
type: "close"
wasClean: false
__proto__: CloseEvent

错误与此问题的标题相同.

The error is same with the title of this question.

有一个人遇到了与我类似的问题.Websocket 服务器,基于 socketo.me不接受来自共享互联网的连接

There is one person who got the problem similar to mine. Websocket Server, based on socketo.me not accepting connections from shared internet

推荐答案

问题是我使用的端口是 8082 和 8083 突然被客户端浏览器阻止了.超时错误准确反映了使用非 80 (HTTP) 或 443 (SSL) 的端口连接到我的 Web 套接字服务器失败的结果.原因可能是防火墙,防病毒软件或任何 HTTP 代理问题.

The problem is the port which I was using are 8082 and 8083 suddenly blocked by client browser. The timeout error reflects exactly the result of failure of the connecting to my web socket server with those ports which isn't 80 (HTTP) or 443 (SSL). The cause maybe the firewall, Antiviruses, or any HTTP proxies issue around.

实际上有很多话题人们会注意到这个问题.最终,我不得不找出配置我的服务器的方法,以将端口 80 的请求反向到两个不同的端口:8080(我的 Apache)和8083(网络套接字).

There are actually many topics where people notice about this problem. Eventually, I had to find out the way to configure my server to reverse the request with port 80 to two different ports: 8080 (my Apache) & 8083 (websocket).

Ratchet 的官方网站上也提供了对我有用的解决方法HAProxy

The workaround does work for me is also on the official site of Ratchet HAProxy

这篇关于WebSocket 连接到“ws://mydomain.com:8084/?peer_id=123"失败:连接建立错误:net::ERR_CONNECTION_TIMED_OUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆