public function start() { $packet = new ConnectRequestPacket(); $packet->setProtocolLevel($this->connection->getProtocol()); $packet->setKeepAlive($this->connection->getKeepAlive()); $packet->setClientID($this->connection->getClientID()); $packet->setCleanSession($this->connection->isCleanSession()); $packet->setUsername($this->connection->getUsername()); $packet->setPassword($this->connection->getPassword()); $will = $this->connection->getWill(); if ($will !== null && $will->getTopic() !== '' && $will->getPayload() !== '') { $packet->setWill($will->getTopic(), $will->getPayload(), $will->getQosLevel(), $will->isRetained()); } return $packet; }