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);
};
Above is the piece of code to connect the socket server from client.
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();
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.
In my country, there are four big ISP providers: A,B,C,D
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.
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.
There is one person who got the problem similar to mine. Websocket Server, based on socketo.me not accepting connections from shared internet
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.
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).
The workaround does work for me is also on the official site of Ratchet HAProxy