/** * Called when the HTTP request headers have been received. * * @param HttpRequest $req * @param $success */ public function gotHeaders(HttpRequest $req, $success) { $stream = $req->getStream(); $streamId = $this->streams->getId($stream); // Remove the stream from the list, because the HttpRequest is listening to it. $this->streams->removeStream($streamId); if ($success) { $success = $this->performHandshake($req); } if (!$success) { fclose($stream); return; } // Send the stream events to this class. $streamId = $this->streams->addStream($stream, $streamId, $this); $connection = new ClientConnection($stream, $streamId); $connection->addEventListener($this); $this->connections[$streamId] = $connection; $e = $this->createEvent(WebSocketServer::EVENT_CONNECTED); $e->connection = $connection; $this->notifyEventListeners($e); }