如何解决SSLSocket 的 OutputStream 是“阻塞的”
问题:有时当客户端在发送数据时与我的程序/服务器断开连接时,我的程序的 write 方法会阻塞。
这是我的 write 方法所在的循环:
while(!Thread.currentThread().isInterrupted()) {
/* I have left out the code that generates the data to be sent for a better overview */
try {
// Up to this point the code will run normally
out.write(data.bytes,data.num);
/* Sometimes the code after the write method does not run.
It is like the write method blocks permanently. */
} catch (IOException e) {
break;
}
}
我试图打破封锁...
关闭 SSLSocket,
关闭输入和输出流,
使用flush方法,
在线程上使用中断和连接方法,
并通过读取和写入输入和输出流。
这些都不行。
我注意到当我像这样创建OutputStream时out = new BufferedOutputStream(socket.getOutputStream());
与我这样创建 OutputStream 相比,“阻塞”行为发生的频率要低得多。out = socket.getOutputStream();
我不知道为什么,但有明显的不同。
有没有办法完全防止“阻塞”,或者有没有办法释放“被阻塞”的进程?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。