File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

Problem of flushing Data to SocketOutputStream

kishore routhu
Greenhorn

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
    
    1

Look at that:
http://stackoverflow.com/questions/2208387/java-socket-outputstream-is-not-flushing


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
 
wood burning stoves
 
subject: Problem of flushing Data to SocketOutputStream