Nachrichtenversenden gefixt/Test-Klassen in eigenes Paket
This commit is contained in:
parent
8f2c12dab8
commit
6f39b1ba46
7 changed files with 81 additions and 84 deletions
|
@ -17,7 +17,6 @@
|
|||
package server;
|
||||
|
||||
import utils.FifoPipe;
|
||||
import java.net.Socket;
|
||||
import utils.ArrayHelper;
|
||||
import utils.Message;
|
||||
|
||||
|
@ -53,4 +52,10 @@ public class ClientMessageStore {
|
|||
public synchronized Thread removeThread(Thread thread) {
|
||||
return arrayHelper.popThread(thread, clientThreads);
|
||||
}
|
||||
|
||||
public void notifyAllClients() {
|
||||
for (int i = 0; i < clientThreads.length; i++) {
|
||||
clientThreads[i].interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2021 eichehome
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package server;
|
||||
|
||||
import utils.ArrayHelper;
|
||||
import java.io.IOException;
|
||||
import java.io.PipedReader;
|
||||
import java.io.PipedWriter;
|
||||
import utils.FifoPipe;
|
||||
import utils.Message;
|
||||
import utils.PipeElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author eichehome
|
||||
*/
|
||||
public class PipeTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
FifoPipe pipe = new FifoPipe();
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
Message el = new Message("Christian", "Test");
|
||||
pipe.setElement(el);
|
||||
System.out.println("Angehängt");
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
|
||||
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
|
||||
Message el2 = new Message("Christian", "Test");
|
||||
pipe.setElement(el2);
|
||||
System.out.println("Angehängt2");
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
|
||||
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
|
||||
Message pipeElement = pipe.getNextElement();
|
||||
System.out.println("Oben entnommen");
|
||||
System.out.println("Entnommen Inhalt: " + pipeElement.getData().gebeData());
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
|
||||
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
|
||||
Message pipeElement2 = pipe.getNextElement();
|
||||
System.out.println("Oben entnommen2");
|
||||
System.out.println("Entnommen Inhalt: " + pipeElement2.getData().gebeData());
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
//Wieso wills nicht funktionieren?
|
||||
Message pipeElement3 = pipe.getNextElement();
|
||||
System.out.println("Oben entnommen3");
|
||||
//System.out.println(pipeElement3.getData().gebeData());
|
||||
System.out.println("Erstes Element: " + pipe.firstElement);
|
||||
System.out.println("Letztes Element: " + pipe.lastElement);
|
||||
|
||||
ArrayHelper test = new ArrayHelper();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -17,9 +17,10 @@
|
|||
package server;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.net.*;
|
||||
import utils.Message;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,19 +36,27 @@ public class ServerHandelClientsThread extends Thread {
|
|||
public void run() {
|
||||
boolean continueLoop = true;
|
||||
while (continueLoop) {
|
||||
try (InputStreamReader in = new InputStreamReader(clientSocket.getInputStream())) {
|
||||
pr = new PrintWriter(clientSocket.getOutputStream());
|
||||
BufferedReader bf = new BufferedReader(in);
|
||||
for(String clientInput = bf.readLine(); clientInput != null; clientInput = bf.readLine()) {
|
||||
System.out.println("client: " + clientInput);
|
||||
pr.write("yes");
|
||||
pr.flush();
|
||||
try (ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
|
||||
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream())) {
|
||||
Message empfangen = null;
|
||||
while ((empfangen = (Message) in.readObject()) != null) {
|
||||
System.out.println("client: " + empfangen);
|
||||
Message message = empfangen;
|
||||
out.writeObject(message);
|
||||
out.flush();
|
||||
}
|
||||
} 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");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (SocketException ex) {
|
||||
System.err.println("Socket geschlossen");
|
||||
continueLoop = false;
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Exeption: " + ex);
|
||||
Logger.getLogger(ServerHandelClientsThread.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue