Can't reach the socket in PHP. What could be the problem?

Good day!
Trying to deal with sockets in PHP. The server script is run through CLI. The socket is created and waits, but the client part can not get through to him. Take hosting on Yandex cloud.
Tell me, what's the problem?

The server scripts (run via CLI)
set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);

define('ADDR', '0.0.0.0');
define('PORT', 889);

if (socket_bind($socket, ADDR, PORT)) {
 echo "Bind OK\n";
}

if (socket_listen($socket, 10)) {
 echo "Listen OK\n";
}

echo "Start server!\n";

while(true) {
 $accept = socket_accept($socket);
 if ($accept) {
 echo 'There are connection! Exit.\n';
socket_close($socket);
die;
}
}


Client script
$(document).ready(function() {
console.log('start');
 // let socket = new WebSocket("ws://echo.websocket.org");
 let socket = new WebSocket("ws://127.0.0.1:889");
console.log(socket);
 socket.onopen = function() {
 message('Connection established');
socket.send('Hello!');
}

 socket.onclose = function() {
 message('Link is buried');
}

 socket.onerror = function(error) {
message('Error');
}

 socket.onmessage = function(event) {
message(event.data);
}
})

function message(text) {
 $('#chat-result').append('<div>' + text + '</div>');
}


UPDATE
Tried through Telnet:
telnet 127.0.0.1 889
Reach out. But via browser does not work(

UPDATE
Question decided!
The problem was that from the same host knocked.
Now everything is OK.
5df16ad54f334390086113.jpeg
April 3rd 20 at 17:34
1 answer
April 3rd 20 at 17:36
Socket and Websocket are different sockets! The fact that you implemented on the backend is to work with the so-called unix sockets and they are irrelevant to Websockets do not have.

The websocket is an enhanced http Protocol.
The websocket server must implement the handshake (hand snack), similar to how the ssh Protocol is used when the keys of authentication.

Your entry websocket, I advise you to take Libu ready to blaze and sockets implementation.
5df16b6dc9c29539960131.jpeg - rickey_Strosin77 commented on April 3rd 20 at 17:39
@rickey_Strosin77, this does not negate the difference https://habr.com/ru/post/209864/ and to be quite convincing rfc https://tools.ietf.org/html/rfc6455 - trinity.Hayes commented on April 3rd 20 at 17:42

Find more questions by tags PHP