目录结构:
服务器端:
/*
*author:hdj
*/
namespace app\Console;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Websocket extends Command{
protected $server;
protected function configure()
{
$this->setName('websocket:start')->setDescription('Start Web Socket Server!');
}
protected function execute(Input $input, Output $output)
{
$serv = new \swoole_server('0.0.0.0',9501);
$serv->set(array('task_worker_num' => 4));
$serv->on('connect', function ($serv, $fd){
echo $fd."客户端已经连接进来了.\n";
});
$serv->on('receive', function($serv, $fd, $from_id, $data) {
<