Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda