/** * Sessoion ID * @return string */ public function sessionID() { if ($this->packet == null) { return 0; } return $this->packet->sessionID(); }
/** * 获取协议名字 * @param CatLib\Constraint\Network\IPacket $packet 协议包 */ protected function getProtoClassName(IPacket $packet) { $protoID = $packet->protoID(); $protoName = $this->getProtoName($protoID); if ($protoName == null) { return null; } $protoName = $this->getPackage() . str_replace($this->protoPrefix, "", $protoName); return "\\" . $protoName; }
/** * 发送一条管道通信 * @param \CatLib\Constraint\Network\IPacket $data 数据 * @param bool $taskwork 是否投递到任务线程 * @return void */ public function sendMessage(IPacket $data, $taskwork = true) { $config = $this->env["swoole"]["config"]; $target = mt_rand($taskwork ? $config["worker_num"] : 0, $taskwork ? $config["worker_num"] + ($config["task_worker_num"] - 1) : $config["worker_num"] - 1); $this->server->sendMessage($data->serialize(), $target); }