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

[BUG]消息丢失 #4

Open
ngtrio opened this issue Dec 4, 2018 · 1 comment
Open

[BUG]消息丢失 #4

ngtrio opened this issue Dec 4, 2018 · 1 comment

Comments

@ngtrio
Copy link

ngtrio commented Dec 4, 2018

while ((size = client.read(buf)) > 0) {
                    buf.flip();
                    baos.write(buf.array(), 0, size);
                    buf.clear();
 }

在ReadEventHandler中,TCP可能粘包,此处baos存入的可能是多条消息的字节流,反序列化会导致客户端到达的部分消息丢失。(在ReadEventHandler中sleep一下就能看到此bug)

@songxinjianqwe
Copy link
Owner

是的,确实有这个问题。可以先写一个包的长度,再读取这个长度,看后面可以读的字节数有没有这么长,没有的话就全部放回,有的话再读出来

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