my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 804

Look at that:

Consider Paul's rocket mass heater.
subject: Problem of flushing Data to SocketOutputStream
Similar Threads
to read a file and store it
Echo Server
Exception in Socket Server
new to socket programming
SocketException is not throwing in Windows Vista while network lost.