Websocket向所有客户端发送消息

时间:2015-10-15 14:24:43

标签: javascript php websocket

您好我想向所有已连接的客户端发送消息,但我的代码不起作用(对于一个用户来说是好的)

require_once('websockets.php');
$userConnected = array();


class echoServer extends WebSocketServer {

  protected function process ($user, $exec) {
      foreach($userConnected as $u) {
        $this->send($u,'test');
      }
  }

  protected function connected ($user) {
    array_push($userConnected, $user);
  }

  protected function closed ($user) {
    if(($key = array_search($user, $userConnected)) !== false) {
        unset($userConnected[$key]);
    }
  }
}

0 个答案:

没有答案