• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem of flushing Data to SocketOutputStream

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at that:
http://stackoverflow.com/questions/2208387/java-socket-outputstream-is-not-flushing
 
reply
    Bookmark Topic Watch Topic
  • New Topic