swoole udp
server.php
<?php
$server = new swoole_server('127.0.0.1', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
$server->set(array("worker_num"=>4, "dispatch_mode"=>2));
$server->on("connect", function($cli) {
$ser->send("hello");
});
$server->on("receive", function($ser, $fd, $from_id, $data) {
$info = $ser->connection_info($fd, $from_id);
var_dump($info);
$ser->send($fd, "hello", $from_id);
});
$server->start();
client.php
<?php
$client = new swoole_client(SWOOLE_SOCK_UDP);
$client ->connect("127.0.0.1", 9502, 0.5);
$client->send("dddddddddd444444444d");
$data=$client->recv();
echo $data;
查看通信过程
[root@LocalWeb01 ~]# tcpdump -i any udp port
tcpdump: WARNING: Promiscuous mode not supported on the "any" device
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size bytes
::18.545684 IP localhost.localdomain. > localhost.localdomain.: UDP, length
::18.549676 IP localhost.localdomain. > localhost.localdomain.: UDP, length
swoole udp的更多相关文章
- PHP swoole UDP服务端和客户端
服务端 <?php $serv = ,SWOOLE_PROCESS,SWOOLE_SOCK_UDP); $serv->on('Packet',function ($serv,$data,$ ...
- 安装netcat(-bash: netcat: command not found)
安装netcat 在用swoole UDP服务器可以使用netcat -u 来连接测试时,报错-bash: netcat: command not found,是因为centos7未安装netcat. ...
- 【swoole】如何在docker+swoole环境下测试udp服务
前面几篇文章讲了使用 docker+swoole 环境来测试tcp服务以及如何测试,但是当我开始学习udp服务那块的时候,发现使用原来的方式在 docker+swoole 环境下行不通啦,后来发现如果 ...
- swoole深入学习 3. upd Server和udp Client
前面主要讲了tcp得server和client的业务处理,tcp有三次握手,有连接的概览,而UDP服务器与TCP服务器不同,UDP没有连接的概念.启动Server后,客户端无需Connect,直接可以 ...
- Swoole学习(三)Swoole之UDP服务器的创建
环境:Centos6.4,PHP环境:PHP7 <?php //创建UCP服务器(UDP服务器相对于TCP服务器通信更可靠些) /** * $host 是swoole需要监听的ip,如果要监听本 ...
- swoole 创建UDP服务器
udp_server.php <?php // 创建Server对象,监听 127.0.0.1:9502端口,类型为SWOOLE_SOCK_UDP $serv = new swoole_serv ...
- Swoole 中 TCP、UDP 和长连接、短连接
TCP 服务 swoole 文档 - TCP 服务 tcp 服务端 <?php // 1. 创建 swoole 默认创建的是一个同步的阻塞tcp服务 $host = "0.0.0.0& ...
- Swoole 中使用 UDP 异步服务器、UDP 同步客户端、UDP 协程客户端
UDP 异步风格服务器 # udp_server.php // 创建 UDP 服务器对象,监听0.0.0.0:9502端口,类型为SWOOLE_SOCK_UDP $serv = new Swoole\ ...
- Swoole练习 UDP
UDP 服务代码 <?php //创建Server对象,监听 127.0.0.1:9502端口,类型为SWOOLE_SOCK_UDP $serv = new swoole_server(&quo ...
随机推荐
- mysql配置文件my.cnf模板
[client] default-character-set = utf8mb4 port = PORT socket = /srv/myPORT/run/mysql.sock [mysqld] us ...
- Unity3D笔记 GUI 一
要实现的功能: 1.个性化Windows界面 2.减少个性化的背景图片尺寸 3.个性化样式ExitButton和TabButton 4.实现三个选项卡窗口 一.个性化Windows界面 1.1.创建一 ...
- express运行原理
一.express底层:http模块 Express框架建立在node.js内置的http模块上.http模块生成服务器的原始代码如下. var http = require("http&q ...
- 基于pandas python的美团某商家的评论销售(数据分析)
数据初步的分析 本文是该系列的第一篇 数据清洗 数据初步的统计 第二篇 数据可视化 第三篇 数据中的评论数据用于自然语言处理 from pyecharts import Bar,Pie import ...
- POJ-2329 Nearest number - 2(BFS)
Nearest number - 2 Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4100 Accepted: 1275 De ...
- poj3728The merchant 【倍增】【LCA】
There are N cities in a country, and there is one and only one simple path between each pair of citi ...
- 算术平均数 print('arithmeticAverageSingleCompressionRatio:', sum(singleCompressionRatio)/len(singleCompressionRatio))
print('arithmeticAverageSingleCompressionRatio:', sum(singleCompressionRatio)/len(singleCompressionR ...
- Xcode 9运行h d f报错
SocialSDKXib/UMSCommentInputController.xib: error: Illegal Configuration: Compiling IB documents for ...
- WordCount优化
Github 地址:chaosrings/wcPro 1.PSP2.1表格 psp 2.1 psp阶段 预估耗时(分钟) 实际耗时(分钟) Planning 计划 10 10 Estimate 估计这 ...
- Arctic Network---poj2349 最小生成树
http://poj.org/problem?id=2349 题意:有n个点给出坐标,点和点之间可以用无线电或者卫星通信,每个点都有无线电收发器可进行无线电通信,但是只有m个点有卫星通信功能.卫星通信 ...