Chat-Applikation/src/server/MainServer.java

55 lines
1.7 KiB
Java

/*
* 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 java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.net.*;
/**
* Hauptklasse des Servers
*
* @version 0.0.1
* @author eichehome
*/
public class MainServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try (ServerSocket serverSocket = new ServerSocket(1236)) {
ClientMessageStore messageStore = new ClientMessageStore();
while (true) {
Socket client = serverSocket.accept();
System.out.println("client connected");
PipedReader pipeOut = new PipedReader();
PipedWriter pipeIn = new PipedWriter(pipeOut);
Thread thread = new ServerHandelClientsThread(client, messageStore, pipeOut);
System.out.println("Test");
thread.run();
messageStore.addClient(thread, pipeIn);
}
} catch (Exception ex) {
System.err.println("Fehler: " + ex);
}
}
}