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

we can't read data bigger than #3

Closed
BadDeveloper2022 opened this issue Oct 16, 2017 · 11 comments
Closed

we can't read data bigger than #3

BadDeveloper2022 opened this issue Oct 16, 2017 · 11 comments

Comments

@BadDeveloper2022
Copy link

BadDeveloper2022 commented Oct 16, 2017

com.xuhao.android.libsocket.impl.exceptions.ReadException: we can't read data bigger than 10Mb
这个是什么错误啊?我的数据不超过3KB

@xuuhaoo
Copy link
Owner

xuuhaoo commented Oct 16, 2017

这个是防止内存溢出的错误,说明你服务器返回的数据格式不对(包头中的包体长度不正确)

@xuuhaoo
Copy link
Owner

xuuhaoo commented Oct 16, 2017

image
你的Socket服务器应该返回数据格式按照 [包头][包体]的格式,包头中默认的Header处理是直接解析包头数据为后面的包体长度,你可以重写包头解析方法,来适应你的服务器返回,从中返回正确的包体长度,如上图这个方法,是设置自定义包头解析类的

@xuuhaoo
Copy link
Owner

xuuhaoo commented Oct 16, 2017

我已经更新了文档,你可以看下

@BadDeveloper2022
Copy link
Author

每一个包是 \n 来分包的,这个怎么解析?

@BadDeveloper2022
Copy link
Author

还有一个问题:我重写了那个接口,但是不知道当前的接受的数据,怎么知道一个包Body长度呢?

@BadDeveloper2022
Copy link
Author

有时间帮我解决一下,谢谢:QQ 253933559

@xuuhaoo xuuhaoo closed this as completed Oct 17, 2017
@ghost
Copy link

ghost commented Oct 24, 2017

我也是遇到这个问题, 怎么自定义包头和包体 ?

@BadDeveloper2022
Copy link
Author

目前为止好像不支持自定义分包

@ghost
Copy link

ghost commented Oct 24, 2017

QQ 58461882 , 求大佬支援

@ghost
Copy link

ghost commented Oct 24, 2017

或者说这个 服务器 发送的 格式是什么

@xuuhaoo
Copy link
Owner

xuuhaoo commented Oct 24, 2017

例如服务端要给你发送一个英文字母 a
那么服务端应该这样发送 byte 数组
00 00 00 01 61

解释如下:
a 的 Ascll 码对应的是97 97的16进制是0x61
a 的数据长度是1
所以包头要标识后面的包体长度是1
所以包头就是1
因为包头是 int 型,一个 int 型战4个字节
所以,就是00 00 00 01
要发送的数据长度 + 发送的数据
所以就是 00 00 00 01 61

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