Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

23
vendor/swoole/examples/udp/async_client.php vendored Executable file
View 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
View 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
View 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();