Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
outputstream does not write the data as expected

My server looks like this:

package marshexample;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;

public class marshServer {

private ServerSocket ses;
private Reader br;
private OutputStream os;

public marshServer() {

    StringBuilder sb = new StringBuilder();

    try  {
        ses = new ServerSocket(7824);
        Socket s = ses.accept();
        br = new InputStreamReader(s.getInputStream());
        char[] request = new char[6];
        int count = br.read(request);

        while (!sb.toString().contains("project")) {

            sb.append(new String(request, 0, count));
            count = br.read(request);
            System.out.println(sb.toString());
        }
        System.out.println(sb);

        os = s.getOutputStream();
        os.write("string from server".getBytes());
        os.write("empty line".getBytes());
        os.flush();


    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println(sb);

}}

The issue is I have to add the string os.write("empty line".getBytes()); in order to make it work correctly. Without this string the massage is not fully sent to the client. (The same situation is with client). So why flush method does not solve this problem? Thank you for any ideas!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!