首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
在websocket server里面使用定时想客户端发送了ping命令的问题
在websocket server里面使用定时想客户端发送了ping命令的问题, {{{ $server->tick(1000,function() use ($server,$request) { $fd=$request->fd; $server->push($fd,"ping",9); }); }}} 由于将websocket client给关闭了,然后报 {{{ swoole_websocket_server::push(): the connected client of connection[1] is not a websocket client }}} 看了文档https://wiki.swoole.com/wiki/page/490.html,要使用swoole_server::connection_info($fd)来判断是否是有效的websocket client,wiki地址是https://wiki.swoole.com/wiki/page/p-connection_info.html wiki上写明要根据 其中的websocket_status来判断,但是输出connection_info信息后,发现client关闭前后websocket_status这个值都是3, 那么应该依据什么值来判断是否是一个websocket client呢
发布于7年前 · 3 次浏览 · 来自
提问
P
Probe
在websocket server里面使用定时想客户端发送了ping命令的问题, {{{ $server->tick(1000,function() use ($server,$request) { $fd=$request->fd; $server->push($fd,"ping",9); }); }}} 由于将websocket client给关闭了,然后报 {{{ swoole_websocket_server::push(): the connected client of connection[1] is not a websocket client }}} 看了文档https://wiki.swoole.com/wiki/page/490.html,要使用swoole_server::connection_info($fd)来判断是否是有效的websocket client,wiki地址是https://wiki.swoole.com/wiki/page/p-connection_info.html wiki上写明要根据 其中的websocket_status来判断,但是输出connection_info信息后,发现client关闭前后websocket_status这个值都是3, 那么应该依据什么值来判断是否是一个websocket client呢
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2018-12-19
黑
黑凤梨
已经解决了,因为使用了nginx代理了websocket,所以代理以后不能持久连接了,默认隔60秒就断开连接,所以就利用定时器,每一秒钟让websocket server向客户端发送ping数据类型,在server的close()回调中清除这个定时器即可解决,还有个小问题的是,每一个client链接server时都建立了定时器,按理每个client对应的定时器id应该不一样的,但是三个client先后链接上server以后,出现的定时器id为1,1,2,所以有点奇怪,测试结果应该是不影响使用的
赞
0
回复
2018-12-23
勇
勇闯天涯
看来没人回答,对这个答案进行补充一下, {{{ $server->tick(1000,function($id) use ($serv,$request) { $fd=$request->fd; **$flag= $serv->exist($curr_fd)==false || $serv->push($curr_fd,"ping",0x9)==false; if($flag) $serv-
赞
0
回复