客户端请求:
namespace app\index\controller;
class Index
{
public function index()
{
$client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
$ret = $client->connect("192.168.10.10", 9502);
if(empty($ret)) {
echo 'error!connect to swoole_server failed';
} else {
dump('ccc');
$client->send('blue');//这里只是简单的实现了发送的内容
}
echo 'success';
}
}
服务端异步处理:
/**
* Created by PhpStorm.
* Date: 2019/10/30
* Time: 9:54
*/
namespace app\index\controller;
use think\swoole\Server;
class Swoole extends Server
{
protected $host = '0.0.0.0';
protected $port = 9502;
protected $serverType = &