package com.company; import javax.xml.crypto.Data; import java.io.*; import java.net.Socket; import java.util.List; public class Client extends Thread { // Сокет текущего клиента private Socket socket; // Список всех подключенных слиентов private List clientList; public static int READ_BUFFER_SIZE = 1024; public Client(Socket socket, List clientList) throws IOException { this.socket = socket; this.clientList = clientList; } public Socket getSocket() { return socket; } @Override public void run() { while (!isInterrupted()) { try { ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); Transport t = (Transport) ois.readObject(); for (Client client : clientList) { if (client.socket != this.socket) { ObjectOutputStream coos = new ObjectOutputStream(client.socket.getOutputStream()); coos.writeObject(t); coos.flush(); } } System.out.print("\033[1;31m\033[40m " + t.Name + ": \u001B[0m "); System.out.println(t.Message); } catch (IOException | ClassNotFoundException exception) { System.out.println(exception.getMessage()); clientList.remove(this); System.out.println("Disconnected user " + socket.getRemoteSocketAddress().toString()); try { socket.close(); } catch (IOException e) { e.printStackTrace(); } return; } } } }