wood burning stoves 2.0
The moose likes EJB and other Java EE Technologies and the fly likes Problem of flushing Data to SocketOutputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem of flushing Data to SocketOutputStream" Watch "Problem of flushing Data to SocketOutputStream" New topic

Problem of flushing Data to SocketOutputStream

kishore routhu

Joined: Jan 17, 2013
Posts: 14
I am working with Socket (acting as clientSocket) in my Web-Application and this socket is connected to
remote ServerSocket.
Following is the code snippet.

1. PrintWriter socketOutput = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream()), true);
2. BufferedReader SocketInput = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
3. String testFile = "TestFile.xml";
4. File file = new File(testFile);
5. FileReader fr = new FileReader(testFile);
6. BufferedReader br = new BufferedReader(fr);
7. String content = br.readLine();
8. while (content != null) {
10. socketOutput.println(content);
11. content = br.readLine();
12. socketOutput.flush(); // flushing data to Server Socket
13. }
14. socketOutput.close(); //closing SocketOutputStream

Here the clientSocket is flushing each line of data(line:12) to Server Socket
but the serverSocket is not receving it.
And server socket is receiving all the data from file(instead of each line) when
SocketOutputStream is closed from client(line:14).
Please suggest me that how to flush each and every line to ServerSocket(line:12) from
above code.
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 808

Look at that:

BLOG: http://leakfromjavaheap.blogspot.com
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem of flushing Data to SocketOutputStream
It's not a secret anymore!