0
votes
GET ws://echo.websocket.org/ HTTP/1.1
Origin: http://websocket.org
Cookie: __utma=99as
Connection: Upgrade
Host: echo.websocket.org
Sec-WebSocket-Key : uRovscZjNol/umbTt5uKmw==
Upgrade: websocket
Sec-WebSocket-Version: 13

https://www.websocket.org/echo.html

I tried to connect using the above page, but there was no response.

If you have any other way, please let me know.

I was connected to the same network, of course.

1
wss://echo.websocket.org doesn't work. Even the test page you linked to can't connect to it. But if you actually read what the page says, it says "We host a WebSocket Echo Server at ws://demos.kaazing.com/echo," and wss://demos.kaazing.com/echo works fine from that page - Remy Lebeau

1 Answers

1
votes

To connect to wss://echo.websocket.org, using php, without libraries:

<?php  
$sock = stream_socket_client("ssl://echo.websocket.org:443",$e,$n,30,STREAM_CLIENT_CONNECT,stream_context_create(null));
if(!$sock){
 echo"[$n]$e".PHP_EOL;
} else {
  fwrite($sock,"GET / HTTP/1.1\r\nHost: echo.websocket.org\r\nAccept: */*\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: ".rand(0,999)."\r\n\r\n");
  while(!feof($sock)){
    var_dump(fgets($sock,2048));
  }
}

This handles the key handshake for the wss encrypted flux.

Response should looks like:

HTTP/1.1 101 Web Socket Protocol Handshake
Connection: Upgrade
Date: Fri, 15 Nov 2019 05:15:36 GMT
Sec-WebSocket-Accept: wl5g9FOLmrZUguiPZeig/2uiI9o=
Server: Kaazing Gateway
Upgrade: websocket

Same code as a command line:

php -r '$sock=stream_socket_client("ssl://echo.websocket.org:443",$e,$n,30,STREAM_CLIENT_CONNECT,stream_context_create(null));if(!$sock){echo"[$n]$e".PHP_EOL;}else{fwrite($sock,"GET / HTTP/1.1\r\nHost: echo.websocket.org\r\nAccept: */*\r\nConnection: Upgrade\r\nUpgrade: websocket\r\nSec-WebSocket-Version: 13\r\nSec-WebSocket-Key: ".rand(0,999)."\r\n\r\n");while(!feof($sock)){var_dump(fgets($sock,2048));}}'

See other similar usages here