I am confronting a problem with my school project, this code works perfectly:
String adresse = "localhost";
int port = 6565;
new Thread(() -> {
Serveur serveur = new Serveur(port);
Patient ps;
String messageHL7 = serveur.getMessageHL7();
String messageHL7final = serveur.getMessageHL7lisible();
System.out.println("---------------------------------------");
System.out.println("messageHL7final : ");
System.out.println(messageHL7final);
System.out.println("---------------------------------------");
ps = serveur.getPs();
Parser parse = new Parser(messageHL7);
System.out.println("---------------------------------------");
System.out.println("parser : ");
System.out.println(parse.getPatient().getBirth());
System.out.println("---------------------------------------");
serveur.fermeture();
System.out.println("---------------------------------------");
System.out.println("Patient serveur nom de famille : " + ps.getFamillyName());
System.out.println("Patient serveur prénom : " + ps.getFirstName());
System.out.println("Patient serveur IPP : " + ps.getID());
System.out.println("Patient serveur est mort : " + ps.isDeath());
System.out.println("Patient serveur sexe : " + ps.getCharSex());
System.out.println("Patient serveur date de naissance : " + ps.getBirth());
System.out.println("---------------------------------------");
}).start();
DPI dpi = DAOFactory.getDpiDAO().find(new ArrayList<>(Arrays.asList("IPP")), new ArrayList<>(Arrays.asList("170000001")));
Client client = new Client(dpi, adresse, port);
System.out.println("---------------------------------------");
System.out.println("Patient de la base de donnée: " + dpi.toString());
System.out.println("---------------------------------------");
System.out.println("---------------------------------------");
System.out.println("test : ");
Patient p = client.getP();
System.out.println("---------------------------------------");
System.out.println("---------------------------------------");
System.out.println("Patient client nom de famille : " + p.getFamillyName()
+ "\nPatient client prénom : " + p.getFirstName()
+ "\nPatient client sexe : " + p.getCharSex()
+ "\nPatient client date de naissance : " + p.getBirth()
+ "\nPatient clientIPP : " + p.getID()
+ "\nPatient client est mort : " + p.isDeath()
+ "\nPatient client date de décès : " + p.getDeath()
+ "\nPatient client est parti le : " + p.getDateDicharge());
System.out.println("---------------------------------------");
sending me this response:
---------------------------------------
Patient de la base de donnée: Guille Angélique, FEMME, né(e) le 1970-10-21 IPP : 170000001
---------------------------------------
---------------------------------------
test :
---------------------------------------
---------------------------------------
Patient client nom de famille : Angélique
Patient client prénom : Guille
Patient client sexe : F
Patient client date de naissance : Wed Oct 21 19:20:13 CET 1970
Patient clientIPP : 170000001
Patient client est mort : false
Patient client date de décès : null
Patient client est parti le : null
---------------------------------------
year:null
month:null
day:null
hour:null
minutes:null
seconde:null
-------------apresProtocole-----------------
date de naissanceWed Oct 21 19:20:13 CET 1970
---------------------------------------
messageHL7final :
MSH|^~\&|||||20170321192013+0100||ADT^A01|1525900894|P|2.5||||||||||
EVN|A01|20170321192013+0100|||||
PID|1||170000001||Angélique^Guille||19701021192013+0100|F|||||||||||||||||||||N||||||||||||||||||||||
PV1||Inpatient|^^^^^^^^|||^^^^^^^^||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---------------------------------------
year:null
month:null
day:null
hour:null
minutes:null
seconde:null
---------------------------------------
parser :
Mon Nov 21 19:20:13 CET 3870
---------------------------------------
---------------------------------------
Patient serveur nom de famille : Angélique
Patient serveur prénom : Guille
Patient serveur IPP : 170000001
Patient serveur est mort : false
Patient serveur sexe : F
Patient serveur date de naissance : Wed Oct 21 19:20:13 CET 1970
---------------------------------------
but when I tried to decompose the server and the client (I removed the sout):
serveur runable:
int port = 6565;//port d'écoute de mon serveur
new Thread(() -> {
Serveur serveur = new Serveur(port);
Patient ps;
String messageHL7 = serveur.getMessageHL7();
String messageHL7final = serveur.getMessageHL7lisible();
ps = serveur.getPs();
Parser parse = new Parser(messageHL7);
}).start();
and the client runable:
String adresse = "localhost"; //adresse du serveur à joindre
int port = 6565; //port d'écoute du serveur
DPI dpi = DAOFactory.getDpiDAO().find(new ArrayList<>(Arrays.asList("IPP")), new ArrayList<>(Arrays.asList("170000001")));
Client client = new Client(dpi, adresse, port);
Patient p = client.getP();
it bring me back an error:
mars 21, 2017 7:25:02 PM protocole.MinLLPReader getMessage GRAVE: null java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:209) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) at java.io.BufferedReader.readLine(BufferedReader.java:389) at protocole.MinLLPReader.getMessage(MinLLPReader.java:50) at library.interfaces.ServeurHL7.protocole(ServeurHL7.java:84) at interoperabilite.Serveur.(Serveur.java:28) at interoperabilite.TestHL7Serveur.lambda$main$0(TestHL7Serveur.java:24) at java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-0" java.lang.NullPointerException at protocole.MinLLPReader.getMessage(MinLLPReader.java:56) at library.interfaces.ServeurHL7.protocole(ServeurHL7.java:84) at interoperabilite.Serveur.(Serveur.java:28) at interoperabilite.TestHL7Serveur.lambda$main$0(TestHL7Serveur.java:24) at java.lang.Thread.run(Thread.java:745)
So after this I looked on the internet for help but I didn't find a case close to mine. The things that bother me is that it work when they are together but if i take them apart it doesn't.
I looked at this thread: communication between run() method and other class method (java threads) and thus this explanation http://javarevisited.blogspot.fr/2012/07/countdownlatch-example-in-java.html but didn't get the explanation. And I don't even know if this is similar because the final goal is that one computer will run the server code when he require the reception of the HL7 message and the other one run the client code to transmit this message.
sout
the patient details if you only run the server but not the client? Alternatively, does it work if you run both, but delete all the code in the server thread exceptServeur serveur = new Serveur(port);
? – whistling_marmot