How to use websocketd to do 1-to-n communication?

problem description

in Liao Xuefeng"s article introducing websocket, I saw that the server-side software websocketd, instance is 1-to-1. Now I want to expand to 1-to-n. What can I do?

the platform version of the problem and what methods you have tried

http://websocketd.com/

related codes

/ / Please paste the code text below (do not replace the code with pictures)
server:

-sharp!/usr/bin/php
<?php

-sharp Count from 1 to 10 with a sleep
for ($count = 1; $count <= 10; $countPP) {
    echo $count . "\n";
    usleep(500000);
}
?>

client:

$ websocketd --port=8080 my-program    
var ws = new WebSocket("ws://localhost:8080/");

ws.onmessage = function(event) {
  console.log("Count is: " + event.data);
};

debugging passed.

what result do you expect? What is the error message actually seen?

the client browser is logged in by the user, how do I get the server push data that only belongs to me?

Mar.25,2021

Hey, after many years, has this problem been solved? I have encountered the same problem recently. You can solve this problem by getting php $_ SERVER ["UNIQUE_ID"]. Of course, each refresh will generate a new id, for your storage in the database. When you push information to a user, compare that $_ SERVER ["UNIQUE_ID"] is equal to the uid of the database, echo "." .PHP _ EOL;.

Menu