2021-05-11 11:59:08 +00:00
|
|
|
/*
|
2021-05-13 19:09:10 +00:00
|
|
|
* 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/>.
|
2021-05-11 11:59:08 +00:00
|
|
|
*/
|
|
|
|
package server;
|
|
|
|
|
2021-05-13 19:09:10 +00:00
|
|
|
import java.io.IOException;
|
2021-05-15 20:53:58 +00:00
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.ObjectOutputStream;
|
|
|
|
import java.io.PipedInputStream;
|
|
|
|
import java.io.PipedOutputStream;
|
2021-05-14 18:02:26 +00:00
|
|
|
import java.io.PipedReader;
|
|
|
|
import java.io.PipedWriter;
|
2021-05-15 20:53:58 +00:00
|
|
|
import java.lang.invoke.MethodHandles;
|
2021-05-11 11:59:08 +00:00
|
|
|
import java.net.*;
|
2021-05-15 20:53:58 +00:00
|
|
|
import utils.Client;
|
2021-05-14 20:18:23 +00:00
|
|
|
import utils.FifoPipe;
|
2021-05-11 11:59:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Hauptklasse des Servers
|
|
|
|
*
|
|
|
|
* @version 0.0.1
|
|
|
|
* @author eichehome
|
|
|
|
*/
|
|
|
|
public class MainServer {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param args the command line arguments
|
|
|
|
*/
|
|
|
|
public static void main(String[] args) {
|
2021-05-15 20:53:58 +00:00
|
|
|
boolean continueLoop = true;
|
2021-05-13 22:25:42 +00:00
|
|
|
try (ServerSocket serverSocket = new ServerSocket(1236)) {
|
2021-05-15 20:53:58 +00:00
|
|
|
ClientStore clientStore = new ClientStore();
|
|
|
|
while (continueLoop) {
|
|
|
|
System.out.println("Warte auf Clients");
|
2021-05-11 11:59:08 +00:00
|
|
|
Socket client = serverSocket.accept();
|
|
|
|
System.out.println("client connected");
|
2021-05-15 20:53:58 +00:00
|
|
|
|
|
|
|
PipedOutputStream pipedOutputStream = new PipedOutputStream();
|
|
|
|
PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream);
|
|
|
|
|
|
|
|
ObjectOutputStream pipedObjectOutputStream = new ObjectOutputStream(pipedOutputStream);
|
|
|
|
ObjectInputStream pipedObjectInputStream = new ObjectInputStream(pipedInputStream);
|
|
|
|
|
|
|
|
ObjectInputStream in = new ObjectInputStream(client.getInputStream());
|
|
|
|
ObjectOutputStream out = new ObjectOutputStream(client.getOutputStream());
|
|
|
|
|
|
|
|
System.out.println("Streams created");
|
|
|
|
|
|
|
|
Thread threadRecive = new ClientReciveMessageThread(in, clientStore);
|
|
|
|
Thread threadPush = new ClientPushMessageThread(out, pipedObjectInputStream, clientStore);
|
|
|
|
|
|
|
|
System.out.println("Threads created");
|
|
|
|
|
|
|
|
threadPush.start();
|
|
|
|
threadRecive.start();
|
|
|
|
|
|
|
|
System.out.println("Threads started");
|
|
|
|
|
|
|
|
Client client = new Client(pipedObjectOutputStream, threadPush, threadRecive);
|
|
|
|
System.out.println(client.getPusher() + "/" + client.getReciver() + "/" + client.getOutputStream());
|
|
|
|
clientStore.addClient(client);
|
|
|
|
|
2021-05-11 11:59:08 +00:00
|
|
|
}
|
2021-05-13 19:09:10 +00:00
|
|
|
} catch (Exception ex) {
|
|
|
|
System.err.println("Fehler: " + ex);
|
2021-05-11 11:59:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|