| 
					
				 | 
			
			
				@@ -0,0 +1,79 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.company; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.DataOutputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.ObjectInputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.net.Socket; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Random; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class Client extends Thread { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final String[] clientAddressList = new String[]{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.82", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.83", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.84", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.85", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.86", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.87", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.88", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.89", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.90", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "192.168.10.91", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final char []smiles = new char[] { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            '☺', '☻', '♥', '♦', '♣', '♠', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final Random random = new Random(System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void run() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (String address : clientAddressList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int success = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String studentName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int iteration = 0; iteration < 5; iteration++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Socket socket = new Socket(address, 9125); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    socket.setSoTimeout(2000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    System.out.println("Connected to " + address + "... " + (iteration + 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    char smile = smiles[random.nextInt(smiles.length)]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    dos.writeChar(smile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    dos.flush(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Object o = ois.readObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (o instanceof ReData) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        ReData reData = (ReData) o; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        studentName = reData.lastName + " " + reData.firstName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if (reData.firstName.indexOf(smile) != -1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            success++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        reData.PrintName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        System.out.print(" хочет оценку " + reData.appraisal); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        System.out.println(" по дисциплине " + reData.discipline); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    socket.close(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } catch (IOException exception) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (exception.getMessage().contains("Read timed out")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        System.out.println(address + " read timed out... " + (iteration + 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        System.out.println(address + " connecting fail... " + (iteration + 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } catch (ClassNotFoundException exception) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    System.out.println(address + " read data not supported... " + (iteration + 1)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (success == 5) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                System.out.println("\033[32m " + studentName + "\033[0m WIN!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |