Skip to content
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

WebSocket examples #16

Open
YonderChen opened this issue May 9, 2022 · 4 comments
Open

WebSocket examples #16

YonderChen opened this issue May 9, 2022 · 4 comments

Comments

@YonderChen
Copy link
Contributor

There is a problem parsing WS data when the current frame is split into multiple fragments!

@panjf2000
Copy link
Member

Could share some example code?

@YonderChen
Copy link
Contributor Author

Could share some example code?

run main func in file:websocket/server/websocket.go.
use chorme console run js code:
var a = new WebSocket("ws://127.0.0.1:9080/");
a.onmessage = function a(m){console.log(m.data);} ƒ a(m){console.log(m.data);}
a.send("a"); // success! recv res data : a
str=""; for (let index = 0; index < 1024*1024; index++) { str+="a" } a.send(str); // faild!

@YonderChen
Copy link
Contributor Author

大佬是 同胞吗?这个问题应该是 因为 wsutil.ReadClientData 是阻塞读取 conn 里的缓冲区数据。但是gnet OnTraffic 事件的处理协程和 从socket 中读取数据写入conn缓冲区是同一个协程。这就导致了 在 OnTraffic 方法里通过 wsutil.ReadClientData 读取 ws 数据的时候一旦缓冲区的数据不完整 当前协程就被阻塞卡死了。没办法从socket 中继续读取数据写入到 conn的缓冲区

@panjf2000
Copy link
Member

如果是阻塞操作的话那确实不能放到 OnTraffic 里执行,你修复了这个问题吗?如果有时间麻烦提交一个 PR,谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants