JAVA socket closes before sending an ACK

0
  

My code to understand this is a server socket receives a message of "n" lines with hexadecimal characters at the beginning and end (MLLP protocol), but when this buffer is analyzed to pass to string and then pass it to my procedure, it causes the socket closes and I can not send the answer ack

public void run () {     log.info ("The thread starts");     PrintStream writing; // Writing channel     BufferedReader reading; // Reading Channel     String message="";     int pass = 1;     // StringBuffer messageHL7 = new StringBuffer ();     txtOutput.setText ("Starting");     try {       // I create the socket server       log.info ("The socket starts on the port:" + port);       txtOutput.append ("\ nThe socket is started on the port:" + port);       server = new ServerSocket (port);       / Here starts the infinite loop until you stop. /       while (true) {         log.info ("Start loop");         // I invoke the accept method of the server socket, it returns a reference to the client socket         if (pass == 1) {           log.info ("Listening for incoming connections");           txtOutput.append ("\ nListening incoming connections");         }         socket = server.accept ();         // I get a reference to the client socket reading and writing channels         read = new BufferedReader (new InputStreamReader (socket.getInputStream ()));         writing = new PrintStream (socket.getOutputStream ());         // reading of the received message         / - HERE THE PROBLEM: GOES TO STRING THE BUFFER RECEIVED BUT         ---- CAUSES A CLOSURE OF THE SOCKET AND I CAN NOT SEND MY MESSAGE ACK - /         ScannerReaderNoNextTest srnnt = new ScannerReaderNoNextTest ();         message = srnnt.inputStreamToString (socket.getInputStream ());

    //imprime mensaje recibido
    System.out.println("Mensaje recibido: " + mensaje);
    txtOutput.append("\nMensaje recibido: " + mensaje);
    log.info("Mensaje recibido: " + mensaje);
    //mensaje es reemplazado por el ack para ser reenviado al emisor
    String msgack = pr.SET_MENSAJE_HL7(mensaje);
    //Escribo en canal de escritura el ack de confirmacion
    escritura.println(msgack);
    txtOutput.append("\nACK enviado: " + msgack);
    log.info("ACK enviado: " + msgack);
    escritura.close();
    lectura.close();
    socket.close();
    pase++;
  }
} catch (IOException e) {
  log.error("No se pudo crear el socket");
} catch (Exception ex) {
  java.util.logging.Logger.getLogger(HL72018_Recepcion.class.getName()).log(Level.SEVERE, null, ex);
}

}

    
asked by Elí Gamaliel Tarazona marrujo 31.10.2018 в 16:43
source

0 answers