/** * Disconnects the underlying socket, and marks the client as disconnected * * @param int $reason Reason for disconnecting. See Protocol::CLOSE_* * @throws Exception\FrameException * @throws Exception\SocketException */ public function disconnect($reason = Protocol::CLOSE_NORMAL) { $payload = $this->protocol->getClosePayload($reason); if ($this->socket) { $this->socket->send($payload->getPayload()); $this->socket->disconnect(); } $this->connected = false; }
/** * Connect to the Wrench server * * @return boolean Whether a new connection was made */ public function connect() { if ($this->isConnected()) { return false; } $this->socket->connect(); $key = $this->protocol->generateKey(); $handshake = $this->protocol->getRequestHandshake($this->uri, $key, $this->origin, $this->headers); $this->socket->send($handshake); $response = $this->socket->receive(self::MAX_HANDSHAKE_RESPONSE); return $this->connected = $this->protocol->validateResponseHandshake($response, $key); }