server:
$serv = new swoole_server(‘127.0.0.1‘, 9502);
$serv->on(‘receive‘, function ($serv, $fd, $from_id, $data) {
$serv->tick(3000, function() use($serv, $fd) {
$data = "tick-2000ms\n";
$serv->send($fd, $data);
});
});
$serv->start();
client:
$client = new Swoole_client(SWOOLE_SOCK_TCP,SWOOLE_SOCK_ASYNC); $client->connect(‘127.0.0.1‘, 9502, 1);
$cli->send(‘hehe‘);
});
$client->on("receive", function($cli, $data = ""){
if(empty($data)){
$cli->close();
echo "closed\n";
} else {
echo "received: $data\n";
sleep(1);
}
});
$client->on("close", function($cli){
echo "close\n";
});
本文出自 “我是程序我最大” 博客,请务必保留此出处http://skinglzw.blog.51cto.com/10729606/1963961
原文:http://skinglzw.blog.51cto.com/10729606/1963961