tcp 서버 만들기

7612 단어 swoole
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/3
 * Time: 16:00
 */

//  TCP 
$serv = new swoole_server('192.168.1.234', 9502, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

// 
$serv->on('connect', function ($serv, $fd) {
    foreach($serv->connections as $fd)
    {
        $serv->send($fd, "  ".count($serv->connections). "  
"); } echo " ".count($serv->connections). "
"; }); // $serv->on('receive', function ($serv, $fd, $from_id, $data) { print_r($from_id); $serv->send($fd, " ---Server: ".$data); }); // $serv->on('close', function ($serv, $fd) { print_r($serv); foreach($serv->connections as $fd) { $serv->send($fd," ".(count($serv->connections)-1). "
"); } echo " ".(count($serv->connections)-1). "
"; }); // $serv->start();

좋은 웹페이지 즐겨찾기