This commit is contained in:
2020-11-05 18:23:24 +08:00
parent e9f147b36b
commit 3ebec40401
+5 -6
View File
@@ -39,17 +39,16 @@ class OnPacket extends Callback
public function onHandler(Server $server, string $data, array $clientInfo)
{
try {
$client = [$clientInfo['address'], $clientInfo['port']];
$data = DataResolve::unpack($this->unpack, $clientInfo['address'], $clientInfo['port'], $data);
if (empty($data)) {
throw new Exception('Format error.');
}
$client[] = DataResolve::pack($this->pack, $data);
return $server->sendto(...$client);
$client = DataResolve::pack($this->pack, $data);
return $server->sendto($clientInfo['address'], $clientInfo['port'], $client ?? 'Format error');
} catch (\Throwable $exception) {
$client[] = DataResolve::pack($this->pack, $exception->getMessage());
var_dump($client);
return $server->sendto(...$client);
$client = DataResolve::pack($this->pack, $exception->getMessage());
return $server->sendto($clientInfo['address'], $clientInfo['port'], $client ?? 'Format error');
} finally {
$event = Snowflake::app()->event;
$event->trigger(Event::SERVER_WORKER_STOP);