diff --git a/src/Network/UdpClient.php b/src/Network/UdpClient.php index 8b67325..60902f4 100644 --- a/src/Network/UdpClient.php +++ b/src/Network/UdpClient.php @@ -7,7 +7,6 @@ use EasySwoole\Rpc\Config\UdpServiceFinder; use EasySwoole\Rpc\Protocol\UdpPack; use EasySwoole\Rpc\Utility\Openssl; -use Swoole\Coroutine\Client; class UdpClient { @@ -22,7 +21,8 @@ function __construct(UdpServiceFinder $finder,string $clientNodeId) function send(UdpPack $pack,string $address,int $port) { - $client = new Client(SWOOLE_UDP); + $client = new \Swoole\Coroutine\Socket(AF_INET,SOCK_DGRAM); + $client->setOption(SOL_SOCKET, SO_BROADCAST, 1); $client->sendto( $address, $port,$this->pack2string($pack)); } diff --git a/src/Server/AssistWorker.php b/src/Server/AssistWorker.php index a3b63fd..6b2cc4d 100644 --- a/src/Server/AssistWorker.php +++ b/src/Server/AssistWorker.php @@ -54,6 +54,7 @@ function run($arg) $socketServer = new Coroutine\Socket(AF_INET, SOCK_DGRAM); $address = $udpServiceFinderConfig->getListenAddress(); $port = $udpServiceFinderConfig->getListenPort(); + $socketServer->setOption(SOL_SOCKET, SO_REUSEPORT, 1); $socketServer->bind($address,$port); $openssl = null; $secretKey = $udpServiceFinderConfig->getEncryptKey(); diff --git a/tests/ServiceModuleTest.php b/tests/ServiceModuleTest.php index 30894d7..fc82eae 100644 --- a/tests/ServiceModuleTest.php +++ b/tests/ServiceModuleTest.php @@ -77,7 +77,9 @@ function testOnException() private function buildClient($path = '/') { - $client = new \Swoole\Coroutine\Http\Client('127.0.0.1', 9501); + $list = [9501, 9502]; + $port = $list[array_rand($list,1)]; + $client = new \Swoole\Coroutine\Http\Client('127.0.0.1', $port); $client->get($path); return $client; }