WebSocket

The WebSocket technology allows bi-directional communication between a client and the server, through a persistent TCP connection. Events based, the server can choose to which clients to instantaneously send data anytime as long as the clients are online. This makes it suitable for streaming applications such as games and chat rooms.

Below, app.js is a Node.js application file that hosts a Web Socket securely over wss on port 443. You will need to download the file socket.io.js for the client to run on a browser.
// app.js (server)
var express = require('express');
var app = express();
var router = express.Router();
var fs = require('fs');
var https = require('https');
app.get('/:file', function(req,res,next){
   res.send(fs.readFileSync(req.params.file,'utf-8'));
});
var ssl_options = {
   ca: [fs.readFileSync('../ssl/cert1.crt','utf-8'),
        fs.readFileSync('../ssl/cert2.crt','utf-8'),
        fs.readFileSync('../ssl/cert3.crt','utf-8')],
   key: fs.readFileSync('../ssl/mykey.key','utf-8'),
   cert: fs.readFileSync('../ssl/mycert.crt','utf-8')
};
var server = https.createServer(ssl_options,app);
server.listen(443,"0.0.0.0");
global.io = require('socket.io').listen(server);
io.on('connection', socket => {
   var room = socket.handshake['query']['room'];
   var user = socket.handshake['query']['username'];
   socket.join(room);
   socket.on('event1', function(data) {
      io.to(room).emit('message', { msg: user+' has arrived.'}, data);
   });
   socket.on('error', function(err) {}); // built-in event
   socket.on('disconnect', function(err) {}); // built-in event
});

// websocket.html (client)
<!DOCTYPE html><html>
<body>
   <script src="socket.io.js"></script>
   <script>
      const socket = io('wss://mysite.com:443?username=Aladdin&room=my_room');
      socket.on('connect', () => {
         socket.emit('event1', 'xxx', { 'mr': 'john' }, Uint8Array.from([1, 2, 3, 4]));
      });
      socket.on('message', data => {
         console.log(data); // {msg: "Aladdin has arrived."}
      });
   </script>
</body></html>

To run the Node.js application:

npm init -y npm install express socket.io node app.js

Then launch the site on a browser by entering into the address box:

https://mysite.com/websocket.html

Client-side events for 'socket' object: connect, error, disconnect, reconnect, reconnect_attempt, reconnecting, reconnect_error, reconnect_failed

The following cheat sheet summarizes the different ways to emit a message from the server.
io.on('connect', onConnect);
function onConnect(socket){     
  socket.emit('hello', 'can you hear me?', 1, 2, 'abc');      // sending to the client
  socket.broadcast.emit('broadcast', 'hello friends!');       // sending to all clients except sender
  socket.to('game').emit('nice game', "let's play a game");   // sending to all clients in 'game' room except sender
  socket.to('game1').to('game2')                              // sending to all clients in 'game1' and/or in 'game2' room, except sender
        .emit('nice game', "let's play a game (too)");       
  io.in('game').emit('big-announcement',                      // sending to all clients in 'game' room, including sender
                     'the game will start soon');             
  io.of('myNamespace').emit('bigger-announcement',            // sending to all clients in namespace 'myNamespace', including sender
                            'the tournament will start soon');  
  io.of('myNamespace').to('room').emit('event', 'message');   // sending to a specific room in a specific namespace, including sender
  io.to(socketId).emit('hey', 'I just met you');  // sending to individual socketid (private message)
                                                  // WARNING: `socket.to(socket.id).emit()` will NOT work,   
                                                  // as it will send to everyone in the room named `socket.id` but the sender. 
                                                  // Please use the classic `socket.emit()` instead.                                                    
  socket.emit('question', 'do you think so?', function (answer) {});  // sending with acknowledgement
  socket.compress(false).emit('uncompressed', "that's rough");        // sending without compression    
  socket.volatile.emit('maybe', 'do you really need it?');   // sending a message that might be dropped if the client is not ready to receive messages
  socket.binary(false).emit('what', 'I have no binaries!');  // specifying whether the data to send has binary data
  io.local.emit('hi', 'my lovely babies');                   // sending to all clients on this node only
  io.emit('an event sent to all connected clients');         // sending to all connected clients
};

PHP scripts can be used to host Web Socket too.