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

接收数据粘包 #1

Closed
xmaihh opened this issue Dec 11, 2018 · 1 comment
Closed

接收数据粘包 #1

xmaihh opened this issue Dec 11, 2018 · 1 comment

Comments

@xmaihh
Copy link
Owner

xmaihh commented Dec 11, 2018

InputStream.available() 这个方法可以在读写操作前先得知数据流里有多少个字节可以读取,
使用时遇到一些麻烦,比如,通讯时,对方明明发来了1000个字节,但是自己的程序调用available()方法却只得到900,或者100,甚至是0, 这是因为串口通讯是间断性的,和波特率有关,一串字节往往分几批进行发送。本地程序调用available()方法有时得到0,这可能是对方还没有响应,也可能是对方已经响应了,但是数据还没有送达本地。对方发送了1000个字节给你,也许分成3批到达,这你就要调用3次available()方法才能将数据总数全部得到。

@guodonghuang
Copy link

为什么我第一次发送数据没有返回,要发2到3次才会有返回,而且返回的数据会重复一部分,求大佬帮忙呀

@xmaihh xmaihh unpinned this issue Jun 12, 2024
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