码迷,mamicode.com
首页 > 其他好文 > 详细

swoole udp

时间:2015-05-08 09:17:28      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

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 9502
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 96 bytes
08:30:18.545684 IP localhost.localdomain.38978 > localhost.localdomain.9502: UDP, length 20
08:30:18.549676 IP localhost.localdomain.9502 > localhost.localdomain.38978: UDP, length 5

 

swoole udp

标签:

原文地址:http://www.cnblogs.com/agang-php/p/4486682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!