Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem of flushing Data to SocketOutputStream

 
kishore routhu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
1
Android Eclipse IDE Java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic