Implementiere die Verteilung von den Nachrichten
This commit is contained in:
parent
e0ee8be9f6
commit
fcb9dc9b5e
4 changed files with 31 additions and 42 deletions
|
@ -20,6 +20,7 @@ import java.io.*;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.net.*;
|
||||
import utils.FifoPipe;
|
||||
import utils.Message;
|
||||
|
||||
/**
|
||||
|
@ -30,14 +31,15 @@ public class ServerHandelClientsThread extends Thread {
|
|||
|
||||
private Socket clientSocket = null;
|
||||
private ClientMessageStore centralMessageStore = null;
|
||||
private PipedReader pipe = null;
|
||||
private FifoPipe pipe = null;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ObjectOutputStream out = null;
|
||||
boolean continueLoop = true;
|
||||
while (continueLoop) {
|
||||
try (ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
|
||||
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream())) {
|
||||
try (ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream())) {
|
||||
out = new ObjectOutputStream(clientSocket.getOutputStream());
|
||||
Message empfangen = null;
|
||||
while ((empfangen = (Message) in.readObject()) != null) {
|
||||
System.out.println("client: " + empfangen);
|
||||
|
@ -47,12 +49,11 @@ public class ServerHandelClientsThread extends Thread {
|
|||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
System.err.println(ex);
|
||||
//for(String clientInput = in.readLine(); clientInput != null; clientInput = in.readLine()) {
|
||||
//}
|
||||
} catch (InterruptedException ex) {
|
||||
System.err.println("test gegkückt");
|
||||
System.err.println(ex);
|
||||
pr.write("Test");
|
||||
Message message = pipe.read();
|
||||
out.writeObject();
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (SocketException ex) {
|
||||
System.err.println("Socket geschlossen");
|
||||
|
@ -66,11 +67,19 @@ public class ServerHandelClientsThread extends Thread {
|
|||
Logger.getLogger(ServerHandelClientsThread.class.getName()).log(Level.SEVERE, null, ex);
|
||||
centralMessageStore.removeClient(this);
|
||||
continueLoop = false;
|
||||
} finally {
|
||||
if(out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Fehler: " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ServerHandelClientsThread(Socket socket, ClientMessageStore messageStore, PipedReader pipe) {
|
||||
public ServerHandelClientsThread(Socket socket, ClientMessageStore messageStore, FifoPipe pipe) {
|
||||
this.clientSocket = socket;
|
||||
this.centralMessageStore = messageStore;
|
||||
this.pipe = pipe;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue