I am trying to open a basic connection to an HL7 server, where I send a request and get an ACK response. This will be done continuously.
- If this runs continuously, when do I close the socket? Am I implementing this correctly in this case?
- If I close the socket, how do I open it again? The javadocs for ConnectionHub states the following:
attach(java.lang.String host, int port, Parser parser,
java.lang.Class<? extends LowerLayerProtocol> llpClass)
Returns a connection to the specified address, opening this connection, if necessary.
However, in real life, he will not open a new connection if it is already closed.
Patient patient = appt.getPatient();
Parser parser = new GenericParser();
Message hl7msg = parser.parse(wlp.getORMString(appt));
ConnectionHub connectionHub = ConnectionHub.getInstance();
Connection connection = connectionHub.attach(serverIP, serverPort,
new PipeParser(), MinLowerLayerProtocol.class);
if (!connection.isOpen()) {
System.out.println("CONNNECTION is CLOSED");
connection = connectionHub.attach(serverIP, serverPort, new PipeParser(),
MinLowerLayerProtocol.class);
if (!connection.isOpen()) {
System.out.println("CONNNECTION is still CLOSED");
}
}
Initiator initiator = connection.getInitiator();
Message response = initiator.sendAndReceive(hl7msg);
String responseString = parser.encode(response);
System.out.println("Received response:\n" + responseString);
connection.close();
:
, , ACK. java.net.SocketException: Socket closed " .
connection.close(), , .