I put websocket on the server, without nodejs.
I use this solution as a server: https://github.com/Doncode/simple_php_websocket_server
I start the server from the browser.
on the client:
var socket = new WebSocket("ws://мой адрес:9000/ws"); socket.onopen = function() { alert("Соединение установлено."); }; socket.onclose = function(event) { if (event.wasClean) { alert('Соединение закрыто чисто'); } else { alert('Обрыв соединения'); } alert('Код: ' + event.code + ' причина: ' + event.reason); }; socket.onmessage = function(event) { alert("Получены данные " + event.data); }; socket.onerror = function(error) { alert("Ошибка " + error.message); }; setInterval(function() { socket.send('msg1'); }, 5000); Connection is established, there are no errors.
But how to make the server respond? He is silent like a fish ...
The library has a function
function websocket_onmessage($keyINsock, $str){ echo "\r\n"; echo "WEBSOCKET_ONMESSAGE[$keyINsock] $str \r\n"; echo "\r\n"; websock_send($keyINsock, $str); //эхо }
As I understand it, it should work after each received message, but this does not happen. How to be? Problem with server?
9000at you strange it seems like by default on the888port it is started judging by docks. - Naumov