学习SWOOLE之TCP客户端

准备工作:
使用VMware软件安装Centos7 安装php7 和swoole扩展

<?php
//创建TCP客户端

$client = new Swoole\Client(SWOOLE_SOCK_TCP);
if (!$client->connect('192.168.80.1', 9505, -1)) {
    exit("connect failed. Error: {$client->errCode}\n");
}
$client->send("hello world TCPSERVER\n");
echo $client->recv();
echo "send over";
$client->close();

使用网络助手搭建TCPSERVER
在这里插入图片描述
使用命令启动TCP客户端
php Client.php
在这里插入图片描述

发布了77 篇原创文章 · 获赞 2 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/u014265398/article/details/104354914