<?php $client = new swoole_client(SWOOLE_SOCK_UDP6); $client->connect('::1', 9502); $client->send("admin"); echo $client->recv() . "\n"; var_dump($client->getsockname()); var_dump($client->getpeername()); $client->sendto('::1', 9502, "admin2"); echo $client->recv() . "\n"; sleep(1);
Console::put("swoole_server->taskwait()", $data and $data == 'taskwaitok'); Console::put("swoole_server->taskWaitMulti()", test_taskWaitMulti($client)); } $client->send("close"); $data = $client->recv(); Console::put("swoole_server->close()", $data == ''); echo "------------------------------------------------------------------\n"; Console::put("swoole_client[TCP]->recv()", true); Console::put("swoole_client[TCP]->recv(256K, MSG_WAITALL)", $sendBigPkgTest); $sockname = $client->getsockname(); Console::put("swoole_client[TCP]->getsockname()", is_array($sockname)); echo "------------------------------------------------------------------\n"; Console::put("swoole_client[TCP]->close()", $client->close()); echo "------------------------------------------------------------------\n"; $client = new swoole_client(SWOOLE_UDP); Console::put("swoole_client[UDP]->connect()", $client->connect('127.0.0.1', 9502)); Console::put("swoole_client[UDP]->send()", $client->send("hello")); $data = $client->recv(); Console::put("swoole_client[UDP]->recv()", $data and $data == 'Swoole: hello'); $peername = $client->getpeername(); Console::put("swoole_client[UDP]->getpeername()", is_array($peername) and $peername['port'] == 9502); echo "------------------------------------------------------------------\n"; /** * Server测试结束,关闭服务器 */ swoole_process::kill($server->pid + 1, SIGTERM); Console::put("swoole_process::kill()"); $status = swoole_process::wait(); Console::put("swoole_process::wait()", $status['pid'] == $server->pid); echo "------------------------------------------------------------------\n"; echo "Swoole UnitTest Finish.\n";