How to use websocket on client side?

Viewed 140

When one user adds an event using API, other users should get an alert about new event

Is it possible to:

send message from client-side when one user adds an event using wss://echo.websocket.org

let socket = new WebSocket('wss://echo.websocket.org');
socket.onopen = () => socket.send('New event');

and get this message from other browser?

let socket = new WebSocket('wss://echo.websocket.org');

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

server-side on PHP

Is there any source based on "How to realize WebSocket server ( PHP )"?

I don't want to send request to server every some inetrval for checking updates, is there any wat to keep connection alive and when got response show alert to the client?

0 Answers
Related