public function recv($length = 128) {
        if($this->socketsEnabled) {
            $data = socket_read($this->socket, $length);

            if ($data === false) {
                $errorCode = socket_last_error($this->socket);
                if (defined('SOCKET_ECONNRESET') &&
                        $errorCode == SOCKET_ECONNRESET) {
                    throw new ConnectionResetException();
                }
                throw new SocketException($errorCode);
            }
        } else {
            $data = fread($this->socket, $length);

            if ($data === false) {
                throw new SocketException('Could not read from socket.');
            }
        }

        return $data;
    }