/
comavp
/
client-server-information-system
Обзор
Документация
Войти
/
comavp
/
client-server-information-system
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Server/src/controller/Controller.java
49 строк
1 KB
Anton
first commit
31 янв 2019, 18:02
31 янв 2019, 18:02
67619a3
Код
Авторство
О чём код?
package controller; import connection.Connection; import model.*; import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; import java.util.Observable; import java.util.Observer; public class Controller implements Observer { private Model model; private ArrayList<Connection> connections = new ArrayList<Connection>(); private Connection currentConnection; public Controller(Model model){ this.model = model; model.addObserver(this); System.out.println("Server started..."); try (ServerSocket server = new ServerSocket(8000)) { while (true) { try { connections.add(new Connection(this, server.accept())); System.out.println("New client connected"); } catch (IOException e){ System.out.println("Connection exception: " + e); } } } catch (IOException e) { throw new RuntimeException(); } } @Override public synchronized void update(Observable o, Object arg) { currentConnection.sendResponse((String)arg); } public synchronized void processRequest(Connection connetion, String request) { currentConnection = connetion; model.helper(request); } public synchronized void deleteConnection(Connection connection) { connections.remove(connection); System.out.println("Working connections: " + connections.size()); } }