Java Socket OutputStream不刷新 [英] Java Socket OutputStream is not flushing

查看:168
本文介绍了Java Socket OutputStream不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java编写基于套接字的服务器.客户端连接到它(一个网络浏览器),服务器发送回一个简单的html代码并设置cookie以识别客户端下次再次连接到它.我正在使用PrintStream写入套接字,但是冲洗不起作用.我可以刷新的唯一方法是使用shutdownoutput或close并都关闭套接字流.但是我不希望那样,因为我在代码中的多个位置多次对其进行读/写操作.怎么办无法从标签获得任何帮助. 我也尝试了其他缓冲作家类,同样的问题.

I am writing a socket-based server in java. A client connects to it(a web-browser) and the server sends back a simple html code and sets cookie to recognize next time client connects to it again. I am using PrintStream to write to the socket , but flush is not working. The only way i can flush is to use shutdownoutput or close and both close the socket stream. But i do not want that because i am readin/writing to it several times in several places in the code. What can do? Could't get any help from the tags. I also tried other buffered writer classes, same problem.

推荐答案

是的,傻问题,您只需要使用pstream.writeln(");因为breader.readLine()读取直到找到"\ n"字符. 因此write()无法正常工作.

Ah yeah , sillyproblem , you just have to use pstream.writeln(""); since breader.readLine() reads until it finds '\n' character. so write() won't work.

这篇关于Java Socket OutputStream不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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