【发布时间】:2015-08-07 08:36:08
【问题描述】:
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);
};
以上是从客户端连接套接字服务器的一段代码。
在服务器上,我使用PHP WebSocket 来设置在后台运行的套接字服务器
$server = IoServer::factory(
new HttpServer(
new WsServer(
new RatchetGlobalServer()
)
),
8084
);
$server->run();
首先,它在我的本地主机上运行良好,我已经将它部署到我的主机上,它也可以运行。但是,当我切换到另一个 ISP 时它不起作用,onOpen 事件没有触发,它抛出错误并最终到达 onclose。
在我国,有四大 ISP 提供商:A、B、C、D
我尝试使用其他一些 ISP(B、C、D)的其他互联网线路,它完全不起作用,但它在我的家庭互联网线路(来自 ISP A)上工作。我必须强调服务器已经位于专用服务器上,它不再位于我的本地主机上。 我的同事可以访问我的网站并看到它运行良好(他们使用与我相同的网络和路由器)
我的路由器上的配置是否只能使事情正常工作?我不知道发生了什么。我试图找出它好几天。
关闭事件带有代码 1006,原因为空:
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
错误与本题题目相同。
有一个人遇到了与我类似的问题。 Websocket Server, based on socketo.me not accepting connections from shared internet
【问题讨论】: