Android TCP读取几行

发布于 2024-11-29 18:11:50 字数 399 浏览 0 评论 0原文

Android TCP Socket 客户端是否会再读取一行响应?

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
response = bufferedReader.readLine();
response = bufferedReader.readLine();
Log.i(TAG, "Response :: " + response);

我无法阅读两行。因为我的服务器会响应 200 确定\n 内容......

并且内容每秒都会流式传输到客户端,我不想每次都连接套接字。 sbd可以帮忙吗?

Does Android TCP Socket Client read one more line the response??

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
response = bufferedReader.readLine();
response = bufferedReader.readLine();
Log.i(TAG, "Response :: " + response);

I cannot read two line. Because my server will response
200 OK \n
Content.......

And the content will stream to the client every seconds, I don't wanna connect the socket every times. Can sbd help??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-12-06 18:11:50

一个将继续读取直到找到空新行的示例:

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
String line = bufferedReader.readLine(); // add first line
while (line != "")
{
    response += line;
    line = bufferedReader.readLine();
}
Log.i(TAG, "Response :: " + response);

An example that will continue to read until an empty new line is found:

inputStreamReader = new InputStreamReader(socket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader); 
String line = bufferedReader.readLine(); // add first line
while (line != "")
{
    response += line;
    line = bufferedReader.readLine();
}
Log.i(TAG, "Response :: " + response);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文