开发者社区> 问答> 正文

swoole websocket 刚起的时候可以连接,一会就不行了 failed?400报错

swoole websocket 刚起的时候可以连接,一会就不行了 
报错是:
failed: Invalid frame header
查了一下 进程是在的

加上了日志
结果报
zm_deactivate_swoole (ERROR 9003): worker process is terminated by exit()/die().、

而且一直在报, 看网上也有很多人遇到相同的情况,可是没找到解决方案,求大神们指点

 

$table = new swoole_table(1024);
        $table->column('fd', swoole_table::TYPE_INT);
        $table->create();


        $serv = new swoole_websocket_server("0.0.0.0", 9502);
        $serv->addlistener('0.0.0.0', 9503, SWOOLE_SOCK_TCP);
        $serv->table = $table;


        $serv->on('Open', function($server, $req) {
            $server->table->set($req->fd, array('fd' => $req->fd));//获取客户端id插入table
            $log =  "connection open: ".$req->fd."\n";
            echo $log;
            Logger::write($log);
        });

    
        $serv->on('Message', function($server, $frame) {
            $fd = $frame->fd;
            $info = $server->connection_info($fd);
            $log = "fd:".$frame->fd." data:".$frame->data."\n";
            echo $log;
            Logger::write($log);
            if( $info['server_port'] == 9503 )
                   $server->push($fd, "you are admin");
             else{
                 $server->push($fd, "this is server");
             }
        });

        $serv->on('Close', function($server, $fd) {
            $log = "connection close: ".$fd."\n";
            $server->table->del($fd); //从table中删除断开的id
            echo $log;
            Logger::write($log);

        });

        $serv->start();

 

 

 

展开
收起
爱吃鱼的程序员 2020-06-08 12:33:39 1129 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    代码中是否包含exit()/die()等函数

    回复 @simple__:我嵌套在我原有的框架之内的,应该是某一块有exit或die,我单独提起出来,貌似可以了,感谢
    2020-06-08 12:33:57
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载