diff --git a/6.1Time/Client.jar b/6.1Time/Client.jar
new file mode 100644
index 0000000..43ebd44
Binary files /dev/null and b/6.1Time/Client.jar differ
diff --git a/6.1Time/Server.jar b/6.1Time/Server.jar
new file mode 100644
index 0000000..20a51af
Binary files /dev/null and b/6.1Time/Server.jar differ
diff --git a/6.1Time/pom.xml b/6.1Time/pom.xml
new file mode 100644
index 0000000..86f4f52
--- /dev/null
+++ b/6.1Time/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ niit
+ 6.1Time
+ 1.0-SNAPSHOT
+
+
+
+
+ src/main/resources
+
+
+
+
+
+
\ No newline at end of file
diff --git a/6.1Time/src/main/java/sample/Controller.java b/6.1Time/src/main/java/sample/Controller.java
new file mode 100644
index 0000000..19afdc7
--- /dev/null
+++ b/6.1Time/src/main/java/sample/Controller.java
@@ -0,0 +1,112 @@
+package sample;
+
+import javafx.application.Platform;
+import javafx.fxml.FXML;
+import javafx.fxml.Initializable;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextField;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.*;
+import java.util.ResourceBundle;
+
+public class Controller implements Initializable {
+
+ @FXML
+ private TextField tfTime;
+ @FXML
+ private TextField tfDate;
+ @FXML
+ private Button btnGet;
+ @FXML
+ private Button btnStop;
+
+ private Socket server;
+ BufferedReader in=null;
+ PrintWriter out=null;
+ private String streamTime;
+
+ @Override
+ public void initialize(URL location, ResourceBundle resources) {
+ streamTime=new String("go");
+ tfTime.setText("HH:MM:SS");
+ tfDate.setText("dd.mm.yyyy");
+ }
+
+ @FXML
+ private void getTimeDate() throws IOException {
+
+ try{
+ server = new Socket("127.0.0.1", 2345);
+ }catch (UnknownHostException e){
+ System.out.println("Unknown host");
+ System.exit(-1);}
+ catch (NoRouteToHostException e){
+ System.out.println("No connection");
+ System.exit(-1);}
+ catch (ConnectException e){
+ System.out.println("Connection error");
+ System.exit(-1); }
+ catch (IOException e){
+ System.out.println("Output-input error");
+ System.exit(-1); }
+
+ try {
+ in=new BufferedReader(new InputStreamReader(server.getInputStream()));
+ out=new PrintWriter(server.getOutputStream(),true);
+
+ }catch (IOException e){
+ System.out.println("Error creating threads");
+ System.exit(-1); }
+
+ new Thread(()->{
+ String fserver;
+ String time=new String("HH:mm:ss");
+ String date=new String("dd.MM.yyyy");
+
+ while(streamTime.equals("go")) {
+ try {
+ out.println(streamTime);
+
+ fserver = in.readLine();
+ time = fserver.substring(0, 8);
+ date = fserver.substring(8);
+ System.out.println(time);
+ System.out.println(date);
+ }catch (IOException e){
+ System.out.println(e);
+ }
+
+ String time1=time;
+ String date1=date;
+ Platform.runLater(()->setTimeDate(time1,date1));//change data to scene
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace(); }
+ }
+ }).start();
+ }
+
+ private void setTimeDate(String time, String date){ //for set time on scene
+ tfTime.setText(time);
+ tfDate.setText(date);
+ }
+
+ private void setStreamTime(String world){ //for stop of time
+ this.streamTime=world;
+ }
+
+ @FXML
+ private void stop() throws IOException {
+
+ setStreamTime("stop");
+ tfTime.setText("");
+ tfDate.setText("");
+ out.close();
+ in.close();
+ server.close();
+ }
+}
diff --git a/6.1Time/src/main/java/sample/Main.java b/6.1Time/src/main/java/sample/Main.java
new file mode 100644
index 0000000..9f277cf
--- /dev/null
+++ b/6.1Time/src/main/java/sample/Main.java
@@ -0,0 +1,25 @@
+package sample;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+public class Main extends Application {
+
+ @Override
+ public void start(Stage primaryStage) throws Exception{
+ Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));
+ Scene scene=new Scene(root);
+ scene.getStylesheets().add(getClass().getResource("/myCSS.css").toExternalForm());
+ primaryStage.setTitle("Time and date");
+ primaryStage.setScene(scene);
+ primaryStage.show();
+ }
+
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
diff --git a/6.1Time/src/main/java/sample/Server.java b/6.1Time/src/main/java/sample/Server.java
new file mode 100644
index 0000000..fddcd80
--- /dev/null
+++ b/6.1Time/src/main/java/sample/Server.java
@@ -0,0 +1,59 @@
+package sample;
+
+import java.io.*;
+import java.net.*;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+public class Server {
+ public static void main(String[] args) throws IOException{
+
+ BufferedReader in=null;
+ PrintWriter out=null;
+ ServerSocket server = null;
+ Socket client=null;
+
+ try {
+ server=new ServerSocket(2345);
+ } catch (IOException e){
+ System.out.println("Connection error with port 2345");
+ System.exit(-1);
+ }
+
+ try{
+ System.out.println("Waiting connection");
+ client=server.accept();
+ System.out.println("Client connected");
+ }catch (IOException e){
+ System.out.println("Unable to establish connection");
+ System.exit(-1);
+ }
+
+ in = new BufferedReader(new InputStreamReader(client.getInputStream()));
+ out=new PrintWriter(client.getOutputStream(),true);
+ String input;
+
+ while((input=in.readLine())!=null) {
+
+ if(input.equalsIgnoreCase("stop"))
+ break;
+
+ String date = new SimpleDateFormat("dd.MM.yyyy").format(Calendar.getInstance().getTime());
+ String time = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime());
+ out.println(time + date);
+ out.flush();
+ System.out.println(time + " " + date);
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace(); }
+ }
+ out.close();
+ in.close();
+ client.close();
+ server.close();
+ }
+
+}
+
diff --git a/6.1Time/src/main/resources/1.jpg b/6.1Time/src/main/resources/1.jpg
new file mode 100644
index 0000000..0b626c7
Binary files /dev/null and b/6.1Time/src/main/resources/1.jpg differ
diff --git a/6.1Time/src/main/resources/2.jpg b/6.1Time/src/main/resources/2.jpg
new file mode 100644
index 0000000..0db9b06
Binary files /dev/null and b/6.1Time/src/main/resources/2.jpg differ
diff --git a/6.1Time/src/main/resources/myCSS.css b/6.1Time/src/main/resources/myCSS.css
new file mode 100644
index 0000000..087b05c
--- /dev/null
+++ b/6.1Time/src/main/resources/myCSS.css
@@ -0,0 +1,18 @@
+.root{
+ -fx-font: bold italic 10pt "LucidaBrightDemiBold";
+ -fx-background-image: url("2.jpg");
+}
+
+.text-field{
+ -fx-font: bold italic 20pt "LucidaBrightDemiBold";
+ -fx-padding: 6 6 6 6;
+ -fx-text-fill: green;
+ -fx-background-color: white;
+}
+
+.button{
+ -fx-border-color: rgba(255, 255, 255, 1.80);
+ -fx-border-radius: 8;
+ -fx-background-color: white;
+ -fx-text-fill: green;
+}
diff --git a/6.1Time/src/main/resources/sample.fxml b/6.1Time/src/main/resources/sample.fxml
new file mode 100644
index 0000000..9b4aec8
--- /dev/null
+++ b/6.1Time/src/main/resources/sample.fxml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/6.2MessageInaBottle/pom.xml b/6.2MessageInaBottle/pom.xml
new file mode 100644
index 0000000..e8a2fba
--- /dev/null
+++ b/6.2MessageInaBottle/pom.xml
@@ -0,0 +1,20 @@
+
+
+ 4.0.0
+
+ niit
+ 6.2Aphorism
+ 1.0-SNAPSHOT
+
+
+
+
+ src/main/resources
+
+
+
+
+
+
\ No newline at end of file
diff --git a/6.2MessageInaBottle/src/main/java/sample/ClientObserve.java b/6.2MessageInaBottle/src/main/java/sample/ClientObserve.java
new file mode 100644
index 0000000..0855596
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/java/sample/ClientObserve.java
@@ -0,0 +1,34 @@
+package sample;
+
+import java.io.*;
+import java.net.Socket;
+
+public class ClientObserve {
+
+ private Socket server;
+ private BufferedReader in;
+
+ public ClientObserve(Socket socket){
+ this.server =socket;
+ try{
+ in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ }catch (IOException ex){
+ System.out.println("Клиент: Ошибка инициализации потоков");
+ }
+ }
+
+
+ public String getMessage(){
+ String message = null;
+ try{
+ message=in.readLine();
+ System.out.println(message);
+
+ }catch (IOException ex){
+ System.out.println("Клиент: Ошибка передачи данных");
+ }
+
+ return message;
+ }
+
+}
diff --git a/6.2MessageInaBottle/src/main/java/sample/Controller.java b/6.2MessageInaBottle/src/main/java/sample/Controller.java
new file mode 100644
index 0000000..2fcc249
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/java/sample/Controller.java
@@ -0,0 +1,49 @@
+package sample;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextField;
+import javafx.scene.media.Media;
+import javafx.scene.media.MediaPlayer;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URL;
+
+public class Controller {
+
+ @FXML
+ private TextField tfMessage;
+ @FXML
+ private Button btnGetMessage;
+
+ private Socket socket;
+ private ClientObserve client;
+ static final int PORT=1234;
+ static final String HOST="127.0.0.1";
+ Media media;
+
+
+ @FXML
+ private void getMessage() throws IOException {
+
+ try{
+ socket=new Socket(HOST,PORT);
+ }catch (Exception ee){
+ System.out.println("Не удается соединиться с сервером!");
+ return;
+ }
+ System.out.println("Соединение с сервером установлено!");
+
+
+ client=new ClientObserve(socket);
+
+ String newMessage = client.getMessage();
+ socket.close();
+
+ URL resource = sample.Controller.class.getResource("/1.mp3");
+ media = new Media(resource.toString());
+ MediaPlayer mediaPlayer = new MediaPlayer(media);
+ mediaPlayer.play();
+ tfMessage.setText(newMessage);
+ }
+}
diff --git a/6.2MessageInaBottle/src/main/java/sample/Main.java b/6.2MessageInaBottle/src/main/java/sample/Main.java
new file mode 100644
index 0000000..bc043e2
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/java/sample/Main.java
@@ -0,0 +1,25 @@
+package sample;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+public class Main extends Application { //Client
+
+ @Override
+ public void start(Stage primaryStage) throws Exception{
+
+ Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));
+ Scene scene=new Scene(root);
+ scene.getStylesheets().add(getClass().getResource("/myCSS.css").toExternalForm());
+ primaryStage.setTitle("Message in a bottle");
+ primaryStage.setScene(scene);
+ primaryStage.show();
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
diff --git a/6.2MessageInaBottle/src/main/java/sample/ServerObserver.java b/6.2MessageInaBottle/src/main/java/sample/ServerObserver.java
new file mode 100644
index 0000000..60c6380
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/java/sample/ServerObserver.java
@@ -0,0 +1,15 @@
+package sample;
+
+import java.io.*;
+import java.net.Socket;
+
+public class ServerObserver {
+ private Socket client;
+ private PrintWriter out;
+
+ ServerObserver(Socket s) throws IOException {
+ this.client=s;
+ out=new PrintWriter(client.getOutputStream(),true);
+ }
+
+}
diff --git a/6.2MessageInaBottle/src/main/java/sample/jdsServer.java b/6.2MessageInaBottle/src/main/java/sample/jdsServer.java
new file mode 100644
index 0000000..28bf058
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/java/sample/jdsServer.java
@@ -0,0 +1,98 @@
+package sample;
+
+import java.io.*;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Random;
+
+public class jdsServer {
+ static final int PORT=1234;
+ static private ArrayList messageArr=new ArrayList();
+
+ public static void main(String[] args) throws IOException {
+
+ ServerSocket serverSocket=null;
+ try{
+ URL resource=ServerObserver.class.getResource("/message.txt");
+ File file= Paths.get(resource.toURI()).toFile();
+ FileReader fr= new FileReader(file);
+ BufferedReader reader=new BufferedReader(fr);
+ String line=null;
+ while((line=reader.readLine())!=null){
+ messageArr.add(line);
+ }
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ int size=messageArr.size()-1;
+
+ try {
+ serverSocket=new ServerSocket(PORT);
+ } catch (IOException e){
+ System.out.println("Ошибка связывания с портом "+PORT);
+ System.exit(-1);
+ }
+ System.out.println("Многопоточный сервер стартовал!");
+
+ try{
+ while(true){
+
+ Socket client=serverSocket.accept();
+ try{
+ System.out.println("Новое соединение установлено!");
+ System.out.println("Данные клиента: "+client.getInetAddress());
+ new ServerOne(client, messageArr,size);
+ }catch (IOException e){
+ client.close();
+ }
+ }
+ }finally {
+ serverSocket.close();
+ }
+ }
+}
+
+class ServerOne extends Thread{
+ private Socket client;
+ private PrintWriter out;
+ private ServerObserver cu;
+ private ArrayList messageArr;
+ private int max;
+
+
+ public ServerOne(Socket s, ArrayList messageArr, int max) throws IOException{
+ client=s;
+ this.messageArr=messageArr;
+ this.max=max;
+ out=new PrintWriter(client.getOutputStream(),true);
+ start();
+ }
+
+ public void run(){
+ try{
+ cu=new ServerObserver(client);
+
+ Random random = new Random();
+ int j = random.nextInt(max);
+
+ out.println(messageArr.get(j));
+ }catch (IOException ex){
+ System.err.println("Ошибка чтения записи.");
+ }
+ finally {
+ try{
+ client.close();
+ System.err.println("Соединение закрыто.");
+ }catch (IOException ex){
+ System.err.println("Сокет не закрыт!");
+ }
+ }
+ }
+}
diff --git a/6.2MessageInaBottle/src/main/resources/1.mp3 b/6.2MessageInaBottle/src/main/resources/1.mp3
new file mode 100644
index 0000000..f6a3b1c
Binary files /dev/null and b/6.2MessageInaBottle/src/main/resources/1.mp3 differ
diff --git a/6.2MessageInaBottle/src/main/resources/2.jpg b/6.2MessageInaBottle/src/main/resources/2.jpg
new file mode 100644
index 0000000..5da5ddf
Binary files /dev/null and b/6.2MessageInaBottle/src/main/resources/2.jpg differ
diff --git a/6.2MessageInaBottle/src/main/resources/message.txt b/6.2MessageInaBottle/src/main/resources/message.txt
new file mode 100644
index 0000000..180e5c3
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/resources/message.txt
@@ -0,0 +1,35 @@
+О чем молимся, то и получаем.
+Помни, что каждый день — первый в оставшейся части жизни.
+Обратная сторона кризиса — новые возможности.
+Не каждый может быть твоим другом, но каждый - твоим учителем.
+Когда Бог закрывает дверь, он открывает окно.
+Дорога в тысячу миль начинается с первого шага.
+Никогда не бойся делать то, что ты не умеешь.
+Лучше жалеть о том, что сделал, а не о том, чего нет.
+Кто стоит на месте, тот идёт назад.
+Один раз везет только дуракам. Умным везет всегда.
+Если думаешь — не говори.
+Если думаешь и говоришь — не пиши.
+Если думаешь, говоришь, пишешь — не подписывайся.
+Если думаешь,говоришь,пишешь и подписываешься—не удивляйся.
+Никогда не отказывайся от своей мечты.
+Если ты родился без крыльев — не мешай им расти.
+Вы уникальны, так же, как и все остальные.
+Каково предназначение Человека? Быть им.
+Жизнь — это чудо, дарованное нам свыше.
+Вас обдувает ветер странствий.
+Вы рискуете влюбиться... в ЖИЗНЬ!
+Если Вы проявите инициативу, успех не заставит себя ждать.
+Ваши надежды сбудутся сверх всяких ожиданий!
+Ведите обычную жизнь необычным способом.
+Если колодец засорен, то самое время его очистить.
+Пришло время закончить старое и начать новое.
+Наслаждайтесь удачей и делитесь ею с окружающими.
+Живите в настоящем.
+Будьте настойчивы в битве с собственным эгоизмом.
+Лучше короткий карандаш, чем длинная память.
+И вдохновенья берега откроют Вам свои объятья...
+Моложе, чем сегодня, мы уже не будем...
+Наслаждайтесь жизнью!
+Не дай голодающему рыбы, дай ему удочку!
+А жизнь... Она прекрасна!!! Без сомнений!
\ No newline at end of file
diff --git a/6.2MessageInaBottle/src/main/resources/myCSS.css b/6.2MessageInaBottle/src/main/resources/myCSS.css
new file mode 100644
index 0000000..9e53800
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/resources/myCSS.css
@@ -0,0 +1,18 @@
+.root{
+ -fx-font: bold italic 13pt "LucidaBrightDemiBold";
+ -fx-background-image: url("2.jpg");
+}
+
+.text-field{
+ -fx-font: bold italic 13pt "LucidaBrightDemiBold";
+ -fx-padding: 6 6 6 6;
+ -fx-text-fill: red;
+ -fx-background-color: white;
+}
+
+.button{
+ -fx-border-color: rgba(255, 255, 255, 1.80);
+ -fx-border-radius: 8;
+ -fx-background-color: white;
+ -fx-text-fill: red;
+}
diff --git a/6.2MessageInaBottle/src/main/resources/sample.fxml b/6.2MessageInaBottle/src/main/resources/sample.fxml
new file mode 100644
index 0000000..32a31ed
--- /dev/null
+++ b/6.2MessageInaBottle/src/main/resources/sample.fxml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/6.3MultiServer/Client.jar b/6.3MultiServer/Client.jar
new file mode 100644
index 0000000..10d6e52
Binary files /dev/null and b/6.3MultiServer/Client.jar differ
diff --git a/6.3MultiServer/Server.jar b/6.3MultiServer/Server.jar
new file mode 100644
index 0000000..e3ddb47
Binary files /dev/null and b/6.3MultiServer/Server.jar differ
diff --git a/6.3MultiServer/src/Client.java b/6.3MultiServer/src/Client.java
new file mode 100644
index 0000000..79673a7
--- /dev/null
+++ b/6.3MultiServer/src/Client.java
@@ -0,0 +1,83 @@
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ConnectException;
+import java.net.NoRouteToHostException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+public class Client {
+ static final int PORT=1234;
+ static final int MESSAGES=3; //waiting 3 messages from server
+
+ public static void main(String[] args) throws IOException {
+ System.out.println("Клиент стартовал");
+ //String myID=args[1]; //for server FOR JAR
+ String myID=new String("1");
+
+ Socket server = null;
+ //FOR JAR
+ //if (args.length == 0) {
+ // System.out.println("Использование Java Server_IP");
+ // System.exit(-1);
+ //}
+ // System.out.println("Cоединяемся с сервером " + args[0]);
+
+ System.out.println("Cоединяемся с сервером 127.0.0.1");
+
+ try {
+ //server = new Socket(args[0], PORT);
+ server = new Socket("127.0.0.1", PORT);
+ } catch (UnknownHostException e) {
+ System.out.println("Неизвестный хост");
+ System.exit(-1);
+ }
+ catch (NoRouteToHostException e) {
+ System.out.println("Нет связи");
+ System.exit(-1);
+ }
+ catch (ConnectException e) {
+ System.out.println("Ошибка соединения");
+ System.exit(-1);
+ }
+ catch (IOException e) {
+ System.out.println("Ошибка ввода-вывода");
+ System.exit(-1);
+ }
+
+ BufferedReader in=null;
+ PrintWriter out=null;
+
+ try {
+ in=new BufferedReader(new InputStreamReader(server.getInputStream()));
+ out=new PrintWriter(server.getOutputStream(),true);
+ }catch (IOException e){
+ System.out.println("Ошибка создания потоков");
+ System.exit(-1); }
+
+
+ if(!(myID.equals(""))) //if args[1]!=""
+ out.println(myID); //to server my ID
+ else
+ System.exit(-1);
+
+ String fromServer;
+ int countMessage=0;
+ while (true){ //listening to server.
+
+ fromServer=in.readLine();
+ boolean b=(fromServer==null);
+ if(!b){
+ countMessage++;
+ System.out.println(fromServer);
+ }
+ if(countMessage==MESSAGES) //After the third message "exit"
+ break;
+ }
+ out.close();
+ in.close();
+ server.close();
+
+ }
+}
diff --git a/6.3MultiServer/src/Server.java b/6.3MultiServer/src/Server.java
new file mode 100644
index 0000000..024fea5
--- /dev/null
+++ b/6.3MultiServer/src/Server.java
@@ -0,0 +1,119 @@
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import java.io.*;
+import java.net.*;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
+
+public class Server {
+ static final int PORT=1234;
+ static private BufferedReader in;
+ static Map mapMyClients= new HashMap();
+ static Map mapTimeMesToClient=new HashMap();
+
+ public static void main(String[] args) throws IOException {
+ ServerSocket server = new ServerSocket(PORT);
+ System.out.println("Мультипоточный сервер стартовал!");
+
+ try{
+ while (true){
+
+ Socket client=server.accept();
+ in=new BufferedReader(new InputStreamReader(client.getInputStream())); //id of client
+ mapTimeMesToClient.clear();
+
+ try{
+ System.out.println("Новое соединение установлено");
+
+ InetAddress clientAddress=client.getInetAddress();
+ System.out.println("Данные клиента "+clientAddress);
+
+ String clientID =in.readLine();
+ System.out.println("Получено: id = "+clientID);
+
+ for(String id : mapMyClients.keySet())
+ if(id.equals(null))
+ mapMyClients.put(clientID,clientAddress);
+
+ JSONParser parser=new JSONParser(); //read file for this client has this ID
+ try{
+ // URL resource=Server.class.getResource("clients.json");
+ // File file= Paths.get(resource.toURI()).toFile();
+ // FileReader fr= new FileReader(file);
+ //FOR JAR
+ InputStream inputStream = Server.class.getResourceAsStream("clients.json");
+ String fr = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+
+ JSONArray allID=(JSONArray)parser.parse(fr);
+
+ for(Object oneClient : allID) {
+ JSONObject thisClient = (JSONObject) oneClient;
+ String fileID = (String) thisClient.get("id");
+
+ if(fileID.equals(clientID)){
+ JSONArray forMapTimeMes = (JSONArray) thisClient.get("mapTimeMesToClient");
+ for (Object oneMessage : forMapTimeMes) {
+ JSONObject thisMessage = (JSONObject) oneMessage;
+ String timeMessage = (String) thisMessage.get("time");
+ String theMessage = (String) thisMessage.get("message");
+ mapTimeMesToClient.put(timeMessage, theMessage); //for this client
+ }
+ break;
+ }
+ else
+ client.close(); //I don't have messages for this client (ID)
+ }
+
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ new ServerOne(client, mapTimeMesToClient);
+ }catch (IOException e){
+ client.close();
+ }
+ }
+ }
+ finally {
+ server.close();
+ }
+ }
+}
+
+class ServerOne extends Thread{
+ private Socket client;
+ private PrintWriter out;
+ private Map mapTimeMesToClient;
+
+ public ServerOne(Socket s, Map mapTimeMesToClient) throws IOException{
+ client=s;
+ this.mapTimeMesToClient=mapTimeMesToClient;
+ out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())),true);
+ start();
+ }
+
+ public void run() {
+ System.out.println("ServerOne");
+ while (true) {
+ String time = new SimpleDateFormat("HH:mm").format(Calendar.getInstance().getTime());
+ for (String timeId : mapTimeMesToClient.keySet()) {
+ if (time.equals(timeId)) {
+ String line = mapTimeMesToClient.get(timeId);
+ out.println(line);
+ System.out.println("For client message: " + line);
+ }
+ }
+ try {
+ Thread.sleep(60000); //1 min
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ }
+ }
+}
diff --git a/6.3MultiServer/src/clients.json b/6.3MultiServer/src/clients.json
new file mode 100644
index 0000000..7b4c43f
--- /dev/null
+++ b/6.3MultiServer/src/clients.json
@@ -0,0 +1,53 @@
+[
+ {
+ "id":"1" ,
+ "mapTimeMesToClient":[
+ {
+ "time":"14:05",
+ "message":"Good day for smile!"
+ },
+ {
+ "time":"14:06",
+ "message":"Yes?"
+ },
+ {
+ "time":"14:07",
+ "message":"Yes!"
+ }
+ ]
+ },
+ {
+ "id":"2" ,
+ "mapTimeMesToClient":[
+ {
+ "time":"19:00",
+ "message":"Good evening for coffee and dreams!"
+ },
+ {
+ "time":"19:01",
+ "message":"Yes?"
+ },
+ {
+ "time":"19:02",
+ "message":"Yes!"
+ }
+ ]
+ },
+ {
+ "id":"3" ,
+ "mapTimeMesToClient":[
+ {
+ "time":"10:00",
+ "message":"Good morning for actions!"
+ },
+ {
+ "time":"10:01",
+ "message":"Yes?"
+ },
+ {
+ "time":"10:02",
+ "message":"Yes!"
+ }
+ ]
+ }
+]
\ No newline at end of file
diff --git a/6.4Rate/6.4Rate.jar b/6.4Rate/6.4Rate.jar
new file mode 100644
index 0000000..6b8c32d
Binary files /dev/null and b/6.4Rate/6.4Rate.jar differ
diff --git a/6.4Rate/pom.xml b/6.4Rate/pom.xml
new file mode 100644
index 0000000..46385b3
--- /dev/null
+++ b/6.4Rate/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+
+ niit
+ 6.4Rate
+ 1.0-SNAPSHOT
+
+
+
+
+ src/main/resources
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/6.4Rate/src/main/java/sample/Controller.java b/6.4Rate/src/main/java/sample/Controller.java
new file mode 100644
index 0000000..8acafef
--- /dev/null
+++ b/6.4Rate/src/main/java/sample/Controller.java
@@ -0,0 +1,52 @@
+package sample;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.TextField;
+import java.io.IOException;
+
+public class Controller {
+
+ @FXML
+ private Button btnGetRate;
+
+ @FXML
+ private TextField tfDate;
+ @FXML
+ private TextField tfUSD;
+ @FXML
+ private TextField tfJPY;
+ @FXML
+ private TextField tfRUB;
+
+ @FXML
+ private void getRate() throws IOException {
+
+ java.net.URL url = new java.net.URL("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
+ java.util.Scanner sc=new java.util.Scanner(url.openStream()); //European Central Bank
+
+ for(int i=0;i<7;i++)
+ sc.nextLine(); //go to currency
+ String date=sc.nextLine().replaceAll("^.*'(.*)'.*$","$1");
+ tfDate.setText(date);
+ //
+
+ String currencyUSD=sc.nextLine().replaceAll("^.*'.*'.*'(.*)'.*$","$1");
+ tfUSD.setText(currencyUSD);
+ //
+
+ String currencyJPY=sc.nextLine().replaceAll("^.*'.*'.*'(.*)'.*$","$1");
+ tfJPY.setText(currencyJPY);
+ //
+
+ for(int i=0;i<12;i++)
+ sc.nextLine(); //go to RUB
+
+ String currencyRUB=sc.nextLine().replaceAll("^.*'.*'.*'(.*)'.*$","$1");
+ tfRUB.setText(currencyRUB);
+ //
+
+ sc.close();
+ }
+
+}
diff --git a/6.4Rate/src/main/java/sample/Main.java b/6.4Rate/src/main/java/sample/Main.java
new file mode 100644
index 0000000..eef0824
--- /dev/null
+++ b/6.4Rate/src/main/java/sample/Main.java
@@ -0,0 +1,25 @@
+package sample;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+public class Main extends Application {
+
+ @Override
+ public void start(Stage primaryStage) throws Exception{
+ Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));
+ Scene scene=new Scene(root);
+ scene.getStylesheets().add(getClass().getResource("/myCSS.css").toExternalForm());
+ primaryStage.setTitle("Rate");
+ primaryStage.setScene(scene);
+ primaryStage.show();
+ }
+
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
diff --git a/6.4Rate/src/main/resources/2.jpg b/6.4Rate/src/main/resources/2.jpg
new file mode 100644
index 0000000..e2b754d
Binary files /dev/null and b/6.4Rate/src/main/resources/2.jpg differ
diff --git a/6.4Rate/src/main/resources/myCSS.css b/6.4Rate/src/main/resources/myCSS.css
new file mode 100644
index 0000000..51aa182
--- /dev/null
+++ b/6.4Rate/src/main/resources/myCSS.css
@@ -0,0 +1,24 @@
+.root{
+ -fx-font: bold italic 15pt "LucidaBrightDemiBold";
+ -fx-background-image: url("2.jpg");
+}
+
+.text-field{
+ -fx-font: bold italic 15pt "LucidaBrightDemiBold";
+ -fx-padding: 6 6 6 6;
+ -fx-background-color: derive(#2e2e2e, 130%);
+ -fx-text-fill: blue;
+}
+
+.button{
+ -fx-border-color: rgba(250, 250, 250, 1.80);
+ -fx-border-radius: 8;
+ -fx-background-color: derive(#2e2e2e, 130%);
+ -fx-text-fill: blue;
+}
+
+.label{
+ -fx-font: bold italic 15pt "LucidaBrightDemiBold";
+ -fx-background-color: derive(#2e2e2e, 130%);
+ -fx-text-fill: blue;
+}
diff --git a/6.4Rate/src/main/resources/sample.fxml b/6.4Rate/src/main/resources/sample.fxml
new file mode 100644
index 0000000..82d326d
--- /dev/null
+++ b/6.4Rate/src/main/resources/sample.fxml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+