[英]Java/Android - Writing to Outputstream after reading from Inputstream
On my PC i start a Server to send Bytes over Bluetooth to an Android Phone. 在我的电脑上,我启动一个服务器,通过蓝牙将Bytes发送到Android手机。 I am sending Every 10 seconds different Bytes using the same Outputstream.
我使用相同的Outputstream每隔10秒发送不同的字节数。
outputStream.write(buffer);
outputStream.flush();
thisThread.sleep(10000);
buffer being a bytearray which changes every loop 缓冲区是一个bytearray,它改变每个循环
Now i want to read the buffer on the Android Phone: 现在我想读取Android手机上的缓冲区:
while((bytes = inputStream.read(buffer)) != -1) {
//do something
}
//do more
My problem is now that read(buffer) doesnt return -1. 我的问题是,read(buffer)不会返回-1。 How can i notify the Android Phone that the bytes have been transfered so i can do the things i want after the while loop?
如何通知Android手机已经传输了字节,以便我可以在while循环后执行我想要的操作?
Have you tried closing connection on PC side? 您是否尝试在PC端关闭连接? From your example it looks like you have not.
从你的例子看起来你没有。
[edit] if you do not want to close connection on PC side, then send known byte sequence which will indicate to andorid app that PC side finished sending data and ie. [编辑]如果你不想在PC端关闭连接,那么发送已知的字节序列,这将指示PC端完成发送数据的andorid app,即。 is waiting for response
正在等待回应
try this... 尝试这个...
while((bytes = inputStream.read(buffer)) > 0)
{
//
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.