composer gatewayworker自定义协议报错

MicroStudio

gatewayworker自定义通讯协议报错

报错信息:

E:\Php\app_sms>php application\worker\start_register.php application\worker\start_gateway.php application\worker\start_businessworker.php
----------------------- WORKERMAN -----------------------------
Workerman version:4.0.12 PHP version:7.3.21
------------------------ WORKERS -------------------------------
worker listen processes status
Register text://0.0.0.0:1238 1 [ok]

Fatal error: Uncaught Exception: class \Protocols\Sms not exist in E:\Php\app_sms\vendor\workerman\workerman\Worker.php:2319
Stack trace:
.#0 E:\Php\app_sms\vendor\workerman\workerman\Worker.php(2212): Workerman\Worker->parseSocketAddress()
.#1 E:\Php\app_sms\vendor\workerman\gateway-worker\src\Gateway.php(239): Workerman\Worker->__construct('sms://0.0.0.0:8...', Array)
.#2 E:\Php\app_sms\application\worker\start_gateway.php(24): GatewayWorker\Gateway->__construct('sms://0.0.0.0:8...')
.#3 {main}
thrown in E:\Php\app_sms\vendor\workerman\workerman\Worker.php on line 2319
SmsBusinessWorker none 4 [ok]
process E:\Php\app_sms\application\worker\start_gateway.php terminated and try to restart

版本信息:

E:\Php\app_sms>composer show workerman/gateway-worker -i
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
name : workerman/gateway-worker
descrip. :
keywords : communication, distributed
versions : * v3.0.18
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : http://www.workerman.net
source : [git] https://github.com/walkor/GatewayWorker.git 50d3a77deb7f7fb206d641ee0307ae1c41d5d41d
dist : [zip] https://api.github.com/repos/walkor/GatewayWorker/zipball/50d3a77deb7f7fb206d641ee0307ae1c41d5d41d 50d3a77deb7f7fb206d641ee0307ae1c41d5d41d
path : E:\Php\app_sms\vendor\workerman\gateway-worker
names : workerman/gateway-worker

autoload
psr-4
GatewayWorker\ => ./src

requires
workerman/workerman >=3.5.0

E:\Php\app_sms>composer show workerman/workerman -i
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
name : workerman/workerman
descrip. : An asynchronous event driven PHP framework for easily building fast, scalable network applications.
keywords : asynchronous, event-loop
versions : * v4.0.12
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : http://www.workerman.net
source : [git] https://github.com/walkor/Workerman.git 34abfc8550d669965b8a157001fe23a9785fdefc
dist : [zip] https://api.github.com/repos/walkor/Workerman/zipball/34abfc8550d669965b8a157001fe23a9785fdefc 34abfc8550d669965b8a157001fe23a9785fdefc
path : E:\Php\app_sms\vendor\workerman\workerman
names : workerman/workerman

autoload
psr-4
Workerman\ => ./

requires
php >=5.3

suggests
ext-event For better performance.

E:\Php\app_sms>

目录结构:

截图

另外我之前有一个类似项目,但是workerman的版本号时v4.0.10,工作正常,自定义的通讯协议正常工作。我把之前项目vendor/workerman/目录复制到新项目中替换掉新项目也能正常工作了。但是还是想知道新版本怎么样解决这个问题....

2966 2 0
2个回答

MicroStudio

我自己暂时解决办法是:
1.composer create-project topthink/think=5.1. web_sms
2.composer require workerman/gateway-worker
3.composer require workerman/workerman 4.0.10
通过composer正常安装后,再将workerman版本降级到4.0.10。虽然现在能正常使用,但是感觉这样不妥,不知道4.0.13是不是对自定义通讯协议实现方式是否有变更,现有找到的资料不知道如何解决,期待作者大佬帮忙解决一下。

  • 暂无评论
walkor 打赏

更新到4.0.14或者以后的更高版本试下

  • MicroStudio 2020-10-18

    更新到4.0.14问题解决了,感谢!我看现在composer workerman/gateway-worker 关联的workerman版本也更新到4.0.14了。
    另外能否请教一个问题,就是自定义通讯协议时在input方法内,我如果判定首字节不符合报文规范想抛弃掉此部分数据但是又不想让连接断开应该如何做呢。

  • walkor 2020-10-19

    如果你知道抛弃多少字节的数据的话,用$connection->consumeRecvBuffer($length)来抛弃数据。抛弃完之后如果buffer还有数据,重新手动调用input方法,并返回它的返回值,否则返回0

  • MicroStudio 2020-10-19

    额·不好意思还请教一下,就是如何手动调用input方法呢?我处理完$buffer中的数据后直接使用self::input($buffer,$connection);吗?

  • walkor 2020-10-19

    先把抛弃的部分从$buffer里去掉,然后再调用self::input($buffer,$connection);

  • MicroStudio 2020-10-19

    嗯嗯,明白了。感谢感谢!

年代过于久远,无法发表回答
×
🔝