diff --git a/homework7/homework7.iml b/homework7/homework7.iml
new file mode 100644
index 0000000..9465dd8
--- /dev/null
+++ b/homework7/homework7.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework7/out/production/homework7/hw7/Runner.class b/homework7/out/production/homework7/hw7/Runner.class
new file mode 100644
index 0000000..214dc04
Binary files /dev/null and b/homework7/out/production/homework7/hw7/Runner.class differ
diff --git a/homework7/out/production/homework7/hw7/client/Client.class b/homework7/out/production/homework7/hw7/client/Client.class
new file mode 100644
index 0000000..48c7175
Binary files /dev/null and b/homework7/out/production/homework7/hw7/client/Client.class differ
diff --git a/homework7/out/production/homework7/hw7/client/FXMLDocument.fxml b/homework7/out/production/homework7/hw7/client/FXMLDocument.fxml
new file mode 100644
index 0000000..f2afaa7
--- /dev/null
+++ b/homework7/out/production/homework7/hw7/client/FXMLDocument.fxml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework7/out/production/homework7/hw7/client/FXMLDocumentController.class b/homework7/out/production/homework7/hw7/client/FXMLDocumentController.class
new file mode 100644
index 0000000..9eed190
Binary files /dev/null and b/homework7/out/production/homework7/hw7/client/FXMLDocumentController.class differ
diff --git a/homework7/out/production/homework7/hw7/server/ClientHandler.class b/homework7/out/production/homework7/hw7/server/ClientHandler.class
new file mode 100644
index 0000000..d370af2
Binary files /dev/null and b/homework7/out/production/homework7/hw7/server/ClientHandler.class differ
diff --git a/homework7/out/production/homework7/hw7/server/MyServer.class b/homework7/out/production/homework7/hw7/server/MyServer.class
new file mode 100644
index 0000000..4edfbf5
Binary files /dev/null and b/homework7/out/production/homework7/hw7/server/MyServer.class differ
diff --git a/homework7/src/hw7/Runner.java b/homework7/src/hw7/Runner.java
new file mode 100644
index 0000000..e843bb3
--- /dev/null
+++ b/homework7/src/hw7/Runner.java
@@ -0,0 +1,17 @@
+package hw7;
+
+import hw7.client.Client;
+import hw7.server.MyServer;
+import javafx.application.Application;
+
+public class Runner {
+ public static void main(String[] args) {
+ new Thread(() -> new MyServer()).start();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ new Thread(() -> Application.launch(Client.class, args)).start();
+ }
+}
\ No newline at end of file
diff --git a/homework7/src/hw7/client/Client.java b/homework7/src/hw7/client/Client.java
new file mode 100644
index 0000000..590116e
--- /dev/null
+++ b/homework7/src/hw7/client/Client.java
@@ -0,0 +1,24 @@
+package hw7.client;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+public class Client extends Application {
+
+ @Override
+ public void start(Stage stage) throws Exception {
+ Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
+
+ stage.setScene(new Scene(root));
+ stage.setTitle("ChatWindow");
+ stage.show();
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+}
\ No newline at end of file
diff --git a/homework7/src/hw7/client/FXMLDocument.fxml b/homework7/src/hw7/client/FXMLDocument.fxml
new file mode 100644
index 0000000..f2afaa7
--- /dev/null
+++ b/homework7/src/hw7/client/FXMLDocument.fxml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework7/src/hw7/client/FXMLDocumentController.java b/homework7/src/hw7/client/FXMLDocumentController.java
new file mode 100644
index 0000000..74ef2ce
--- /dev/null
+++ b/homework7/src/hw7/client/FXMLDocumentController.java
@@ -0,0 +1,67 @@
+package hw7.client;
+
+import java.net.URL;
+import java.util.ResourceBundle;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.fxml.Initializable;
+import javafx.scene.control.Button;
+import javafx.scene.control.*;
+import java.net.*;
+import java.io.*;
+
+public class FXMLDocumentController implements Initializable {
+
+ private Socket socket;
+
+ private DataInputStream in;
+ private DataOutputStream out;
+
+ @FXML
+ private Button sendButton;
+
+ @FXML
+ private TextArea TextArea;
+
+ @FXML
+ private TextField TextField;
+
+ @FXML
+ private void sendMsg(ActionEvent event) {
+ String str = TextField.getText();
+ try
+ {
+ out.writeUTF(str);
+ TextField.clear();
+ TextField.requestFocus();
+ }
+ catch (IOException ex)
+ {
+ ex.getStackTrace();
+ }
+ }
+ @Override
+ public void initialize(URL url, ResourceBundle rb) {
+
+ try {
+ socket = new Socket("localhost", 12345);
+ in = new DataInputStream(socket.getInputStream());
+ out = new DataOutputStream(socket.getOutputStream());
+
+ new Thread(() -> {
+ try {
+ while(true)
+ {
+ String str = in.readUTF();
+ TextArea.appendText(str + "\n");
+ }
+ }
+ catch (IOException ex) { ex.printStackTrace(); }
+ }).start();
+ }
+ catch(IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/homework7/src/hw7/server/ClientHandler.java b/homework7/src/hw7/server/ClientHandler.java
new file mode 100644
index 0000000..692c4eb
--- /dev/null
+++ b/homework7/src/hw7/server/ClientHandler.java
@@ -0,0 +1,86 @@
+package hw7.server;
+
+import java.net.*;
+import java.io.*;
+
+public class ClientHandler {
+
+ private MyServer server;
+ private Socket socket;
+ private DataInputStream in;
+ private DataOutputStream out;
+ private String clientName;
+
+ private static int counter = 0;
+
+ public ClientHandler(MyServer server, Socket socket)
+ {
+ try{
+ counter++;
+ this.clientName = "user" + Integer.toString(counter);
+ this.server = server;
+ this.socket = socket;
+ this.in = new DataInputStream(socket.getInputStream());
+ this.out = new DataOutputStream(socket.getOutputStream());
+
+
+ new Thread(()-> {
+
+ try
+ {
+ while(true)
+ {
+ String str = in.readUTF();
+
+ System.out.println("A message from a client: " + str);
+
+ if(str.equalsIgnoreCase("/end"))
+ { break; }
+ if(str.startsWith("/w"))
+ {
+ String to = str.split(" ")[1];
+ String msg = str.split(" ")[2];
+ server.wisperMsg(this, to, msg);
+ } else {
+ server.broadcastMsg("[" + this.clientName + "] " + str);
+ }
+ out.flush();
+ }
+ }
+ catch(IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ finally
+ {
+ try
+ { in.close(); }
+ catch(IOException ex) { ex.printStackTrace(); }
+ try
+ { out.close(); }
+ catch(IOException ex) { ex.printStackTrace(); }
+ try
+ { socket.close(); }
+ catch(IOException ex) { ex.printStackTrace(); }
+
+ server.remove_client(this);
+ }
+
+ }).start();
+ }
+ catch(IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public String getClientName() {
+ return this.clientName;
+ }
+
+ public void sendMsg(String msg)
+ {try
+ { out.writeUTF(msg); }
+ catch(IOException ex){ex.printStackTrace(); }
+ }
+}
\ No newline at end of file
diff --git a/homework7/src/hw7/server/MyServer.java b/homework7/src/hw7/server/MyServer.java
new file mode 100644
index 0000000..700ba05
--- /dev/null
+++ b/homework7/src/hw7/server/MyServer.java
@@ -0,0 +1,53 @@
+package hw7.server;
+
+import java.net.*;
+import java.io.*;
+import java.util.Vector;
+public class MyServer {
+
+ private Vector clients;
+
+ public MyServer()
+ {
+ try
+ { ServerSocket serv_socket = new ServerSocket(12345);
+ clients = new Vector<>();
+
+ while(true) {
+ System.out.println("Waiting for a new client!");
+ Socket socket = serv_socket.accept();
+
+ ClientHandler cl = new ClientHandler(this, socket);
+ add_client(cl); }
+ }
+ catch(IOException ex) { ex.printStackTrace(); }
+ }
+
+ public void add_client(ClientHandler client)
+ {
+ clients.add(client);
+ }
+
+ public void remove_client(ClientHandler client)
+ {
+ clients.remove(client);
+ }
+
+ public void broadcastMsg(String msg)
+ {
+ for(ClientHandler client: clients) {
+ client.sendMsg(msg);
+ }
+ }
+
+ public void wisperMsg(ClientHandler from, String to, String msg)
+ {
+ for (ClientHandler client: clients) {
+ if(client.getClientName().equals(to)) {
+ client.sendMsg("[W from: " + from.getClientName() + "] " + msg);
+ break;
+ }
+ }
+ from.sendMsg("[W to: " + to + "] " + msg);
+ }
+}
\ No newline at end of file