写入Socket outputStream没有关闭它 [英] Writing to Socket outputStream w/o closing it

查看:127
本文介绍了写入Socket outputStream没有关闭它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给服务器写一些消息。
每次,仅对于tramsmitting,我关闭outputStream并在必须发送下一条消息时重新打开它。

I'd like to write some messages to the server. Each time, for the tramsmitting only, I'm closing the outputStream and reopen it when I have to send the next message.

os.write(msgBytes);
os.write("\r\n".getBytes());
os.flush();
os.close();

如何保持此Socket的OutputStream,os,打开并仍能发送消息?

How Can I keep this Socket's OutputStream, os, open and still be able to send the message?

谢谢。

推荐答案

我在这里遗漏了一些东西。如果你不打电话,它将不会关闭。例如,

I am missing something here. If you don't call close, it will not close. For example,

os.write(msgBytes);
os.write("\r\n".getBytes());
os.flush();
// Do something 
os.write("more message");
os.flush();
// When you are finally done
os.close();

这篇关于写入Socket outputStream没有关闭它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆