You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
23
vendor/swoole/examples/udp/async_client.php
vendored
Executable file
23
vendor/swoole/examples/udp/async_client.php
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_UDP, SWOOLE_SOCK_ASYNC); //异步非阻塞
|
||||
|
||||
$client->on("connect", function(swoole_client $cli) {
|
||||
echo "connected\n";
|
||||
$cli->send("hello world\n");
|
||||
});
|
||||
|
||||
$client->on('close', function($cli){
|
||||
echo "closed\n";
|
||||
});
|
||||
|
||||
$client->on('error', function($cli){
|
||||
echo "error\n";
|
||||
});
|
||||
|
||||
$client->on("receive", function(swoole_client $cli, $data){
|
||||
echo "received: $data\n";
|
||||
sleep(1);
|
||||
$cli->send("hello_".rand(1000,9999));
|
||||
});
|
||||
|
||||
$client->connect('127.0.0.1', 9502, 0.5);
|
6
vendor/swoole/examples/udp/client.php
vendored
Executable file
6
vendor/swoole/examples/udp/client.php
vendored
Executable file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$client = new swoole_client(SWOOLE_SOCK_UDP, SWOOLE_SOCK_SYNC);
|
||||
$client->connect('127.0.0.1', 9905);
|
||||
$client->send(serialize(['hello' => str_repeat('A', 600), 'rand' => rand(1, 100)]));
|
||||
echo $client->recv() . "\n";
|
||||
sleep(1);
|
14
vendor/swoole/examples/udp/server.php
vendored
Executable file
14
vendor/swoole/examples/udp/server.php
vendored
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$server = new swoole_server('0.0.0.0', 9905, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
|
||||
for ($i = 0; $i < 20; $i++)
|
||||
{
|
||||
$server->listen('0.0.0.0', 9906 + $i, SWOOLE_SOCK_UDP);
|
||||
}
|
||||
$server->set(['worker_num' => 4]);
|
||||
|
||||
$server->on('Packet', function (swoole_server $serv, $data, $addr)
|
||||
{
|
||||
$serv->sendto($addr['address'], $addr['port'], "Swoole: $data", $addr['server_socket']);
|
||||
});
|
||||
|
||||
$server->start();
|
Reference in New Issue
Block a user