Skip to content

Commit

Permalink
Merge pull request #29 from gaobinzhan/5.x
Browse files Browse the repository at this point in the history
fix: udp broadcast
  • Loading branch information
kiss291323003 authored Dec 18, 2020
2 parents cfa8485 + d6610b5 commit 4fcf723
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Network/UdpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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));
}

Expand Down
1 change: 1 addition & 0 deletions src/Server/AssistWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion tests/ServiceModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4fcf723

Please sign in to comment.