It's only been two.
Four clients have been opened ...
Push ($FD, $msg); }}}//Listen WebSocket connection Open event $ws->on (' Open ', function (Swoole_websocket_server $ws, $request) use (& $fds) {$fds [$r EQUEST->FD] = $request->fd; $ws->push ($request->fd, "Welcome to the small Mon chat platform \ n"); Broadcast ($WS, "User {$request->fd} is logged in! ", $fds, $request->fd); Var_dump ($fds);}); /Listen for WebSocket message Event $ws->on (' Message ', function (Swoole_websocket_server $ws, $frame) use (& $fds) {$msg = ' from '. $ Frame->fd. ": {$frame->data}\n"; Broadcast ($WS, $msg, $fds, $frame->fd); $ws->push ($frame->fd, "server: {$frame->data}"); $ws->push ($frame->fd, "server: {$frame->data}"); /monitor WebSocket connection Shutdown Event $ws->on (' Close ', function (Swoole_websocket_server $ws, $FD) use (& $fds) {unset ($fds [$FD]); Broadcast ($WS, "user {$FD} offline!" ", $fds);}); $ws->start ();
Reply content:
It's only been two.
Four clients have been opened ...
Push ($FD, $msg); }}}//Listen WebSocket connection Open event $ws->on (' Open ', function (Swoole_websocket_server $ws, $request) use (& $fds) {$fds [$r EQUEST->FD] = $request->fd; $ws->push ($request->fd, "Welcome to the small Mon chat platform \ n"); Broadcast ($WS, "User {$request->fd} is logged in! ", $fds, $request->fd); Var_dump ($fds);}); /Listen for WebSocket message Event $ws->on (' Message ', function (Swoole_websocket_server $ws, $frame) use (& $fds) {$msg = ' from '. $ Frame->fd. ": {$frame->data}\n"; Broadcast ($WS, $msg, $fds, $frame->fd); $ws->push ($frame->fd, "server: {$frame->data}"); $ws->push ($frame->fd, "server: {$frame->data}"); /monitor WebSocket connection Shutdown Event $ws->on (' Close ', function (Swoole_websocket_server $ws, $FD) use (& $fds) {unset ($fds [$FD]); Broadcast ($WS, "user {$FD} offline!" ", $fds);}); $ws->start ();