8000 升级到v2.0.6后 ws服务总是会自动将请求返回 · Issue #1002 · swoft-cloud/swoft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

升级到v2.0.6后 ws服务总是会自动将请求返回 #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cirvor opened this issue Sep 25, 2019 · 8 comments · Fixed by swoft-cloud/swoft-component#522
Closed

升级到v2.0.6后 ws服务总是会自动将请求返回 #1002

cirvor opened this issue Sep 25, 2019 · 8 comments · Fixed by swoft-cloud/swoft-component#522
Assignees
Milestone

Comments

@cirvor
Copy link
cirvor commented Sep 25, 2019
Q A
Bug report? yes
Feature request? no
Swoft version v2.0.6
Swoole version 4.4.5
PHP version 7.2.22
Runtime environment Mac
发送消息 13:34:38

{
  "cmd":"home.ping",
  "data":"he",
  "ext":[
    1,
    2,
    3
  ]
}

收到消息 13:34:38

{
  "status":200,
  "event":"PING",
  "data":"PONG"
}

收到消息 13:34:38

{
  "cmd":"home.ping",
  "data":null,
  "ext":[
  ]
}

第二个返回消息是框架自动返回的
且返回的请求数据中 data与ext的值都为空 说明获取到的请求数据并不完整
已回滚到2.0.5 一切正常
服务使用了使用了WsModule
请问有关闭的方法嘛?谢谢

@cirvor
Copy link
Author
cirvor commented Sep 25, 2019

swoft/websocket-server/src/WsMessageDispatcher.php 这个文件

// Do send response
$response->send();

把这个注释掉就不会自动返回了 控制器中的返回正常
但是不知道会不会影响到别的功能

@inhere
Copy link
Member
inhere commented Sep 25, 2019

@cirvor 你在message action 里怎么响应消息的呢?

@inhere inhere self-assigned this Sep 25, 2019
@inhere inhere added this to the v2.0.7 milestone Sep 25, 2019
@cirvor
Copy link
Author
cirvor commented Sep 25, 2019

@inhere

public function ping(): void
{
   Session::mustGet()->push(json_encode([
       'status' => 200,
       'event' => 'PING',
       'data' => 'PONG',
   ]));
}

@inhere
Copy link
Member
inhere commented Sep 25, 2019

@cirvor 谢谢。

v2.0.6 有这个问题,自动响应时没有过滤空值。下个版本修复。

你在后面再加一句,防止再自动响应一次可以解决:

context()->getResponse()->setSent(true);

@cirvor
Copy link
Author
cirvor commented Sep 25, 2019

@inhere
好的 不客气呢

@inhere
Copy link
Member
inhere commented Sep 25, 2019

也可以这样替代现在的使用,就没问题:

public function ping(): void
{
   context()->getResponse()->setContent(json_encode([
       'status' => 200,
       'event' => 'PING',
       'data' => 'PONG',
   ]));
}

// OR
public function ping(Response $response): void
{
	$response->setContent(json_encode([
       'status' => 200,
       'event' => 'PING',
       'data' => 'PONG',
   ]));
}

@luckart
Copy link
luckart commented Sep 25, 2019

我说怎么会出现错误,老铁搞死我了。

@cirvor cirvor closed this as completed Sep 26, 2019
@fredmanxu
Copy link

mark

@inhere inhere added the bug label Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0