|
|
|
|
|
|
|
|
protected PrintWriter writer; |
|
|
protected PrintWriter writer; |
|
|
|
|
|
|
|
|
private Nachricht nachricht; |
|
|
private Nachricht nachricht; |
|
|
|
|
|
private String txtNachricht; |
|
|
private boolean laufend; |
|
|
private boolean laufend; |
|
|
private SubmissionPublisher<Nachricht> textPublisher; |
|
|
private SubmissionPublisher<Nachricht> textPublisher; |
|
|
private ExecutorService eService; |
|
|
private ExecutorService eService; |
|
|
|
|
|
|
|
|
textPublisher = new SubmissionPublisher<>(); |
|
|
textPublisher = new SubmissionPublisher<>(); |
|
|
this.view = view; |
|
|
this.view = view; |
|
|
addWertSubscription(receiveAdapter); |
|
|
addWertSubscription(receiveAdapter); |
|
|
|
|
|
nachricht = new Nachricht(""); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void addWertSubscription(Subscriber<Nachricht> subscriber) |
|
|
public void addWertSubscription(Subscriber<Nachricht> subscriber) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void send(Nachricht nachricht){ |
|
|
|
|
|
|
|
|
|
|
|
writer.println(nachricht.getNachricht()); |
|
|
|
|
|
|
|
|
public void send(String txtNachricht){ |
|
|
|
|
|
|
|
|
|
|
|
writer.println(txtNachricht); |
|
|
writer.flush(); |
|
|
writer.flush(); |
|
|
lg.info("Nachricht gesendet"); |
|
|
lg.info("Nachricht gesendet"); |
|
|
|
|
|
nachricht.setNachricht("\nDu: " + txtNachricht); |
|
|
textPublisher.submit(nachricht); |
|
|
textPublisher.submit(nachricht); |
|
|
} |
|
|
} |
|
|
public Nachricht receive(){ |
|
|
public Nachricht receive(){ |
|
|
Nachricht nachricht = new Nachricht(""); |
|
|
|
|
|
try { |
|
|
try { |
|
|
String txtNachricht = reader.readLine(); |
|
|
|
|
|
|
|
|
txtNachricht = reader.readLine(); |
|
|
if(!txtNachricht.isEmpty()){ |
|
|
if(!txtNachricht.isEmpty()){ |
|
|
lg.info("Nachricht erhalten"); |
|
|
lg.info("Nachricht erhalten"); |
|
|
nachricht.setNachricht("Er / Sie: " + txtNachricht); |
|
|
|
|
|
|
|
|
nachricht.setNachricht("\nEr / Sie: " + txtNachricht); |
|
|
return nachricht; |
|
|
return nachricht; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
while (true) { |
|
|
lg.info("Warte auf Nachricht"); |
|
|
lg.info("Warte auf Nachricht"); |
|
|
if(laufend) { |
|
|
if(laufend) { |
|
|
Nachricht eingehendeNachricht = receive(); |
|
|
|
|
|
if(!eingehendeNachricht.getNachricht().isEmpty()){ |
|
|
|
|
|
textPublisher.submit(eingehendeNachricht); |
|
|
|
|
|
|
|
|
nachricht = receive(); |
|
|
|
|
|
if(!nachricht.getNachricht().isEmpty()){ |
|
|
|
|
|
textPublisher.submit(nachricht); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |