package ru.matevosyan.client;

import java.net.*;
import java.io.*;

public class BotClient {
    public static void main(String[] ar) {
        int serverPort = 19999;
        String address = "127.0.0.1";

        try {
            InetAddress ipAddress = InetAddress.getByName(address);
            System.out.println("Any of you heard of a socket with IP address " + address + " and port " + serverPort + "?");
            Socket socket = new Socket(ipAddress, serverPort);
            System.out.println("Yes! I just got hold of the program.");

            try (
            InputStream sin = socket.getInputStream();
            OutputStream sout = socket.getOutputStream();

            DataInputStream in = new DataInputStream(sin);
            DataOutputStream out = new DataOutputStream(sout);

//            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
//            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in))) {
                String line = "";
                System.out.println("Type in something and press enter. Will send it to the server and tell ya what it thinks.");
                System.out.println();

                while (!line.equals("Пока")) {
                    line = keyboard.readLine();
                    System.out.println("Sending this line to the server...");
                    out.writeUTF(line);

//                    out.write(line);
                    out.flush();

                    line = in.readUTF();
//                    line = in.readLine();
                    System.out.println("The server was very polite. It sent me this : " + line);
                    System.out.println();
                }
            } catch (IOException ioe) {
            ioe.getMessage();
        }
        } catch (Exception x) {
            x.printStackTrace();
        }
    }
}
@@ -91,26 +91,28 @@
 t %7B%0A
+%0A
     p
-ublic
+rivate
  static 
 void
@@ -111,80 +111,64 @@
 tic 
-void main(String%5B%5D ar) %7B%0A        int serverPort = 19999;%0A       
+final int PORT = 19999;%0A    private static final
  String 
 addr
@@ -163,23 +163,23 @@
  String 
-address
+ADDRESS
  = %22127.
@@ -190,213 +190,481 @@
 1%22;%0A
-%0A        try %7B%0A            InetAddress ipAddress = InetAddress.getByName(address);%0A            System.out.println(%22Any of you heard of a socket with IP a
+    private Socket socket;%0A    private static final String SPACE = System.getProperty(%22line.separator%22);%0A%0A    public BotClient(final Socket socket) %7B%0A        this.socket = socket;%0A    %7D%0A%0A    public BotClient() %7B%0A%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A            BotClient botClient = new BotClient();%0A            botClient.startClient();%0A%0A    %7D%0A%0A    public void startClient() %7B%0A%0A        try %7B%0A            InetA
 ddress 
-%22 + a
+ipA
 ddress 
-+ %22 and port %22 + serverPort + %22?%22
+= InetAddress.getByName(ADDRESS
 );%0A 
@@ -674,23 +674,16 @@
         
-Socket 
 socket =
@@ -709,21 +709,17 @@
 ss, 
-serverPort
+PORT
 );%0A
+//
     
@@ -742,18 +742,17 @@
 ut.print
-ln
+f
 (%22Yes! I
@@ -781,17 +781,27 @@
 program.
-%22
+ %25s%22, SPACE
 );%0A%0A    
@@ -814,16 +814,17 @@
   try (%0A
+%0A
         
@@ -925,24 +925,26 @@
 tStream();%0A%0A
+//
             
@@ -990,16 +990,18 @@
 m(sin);%0A
+//
         
@@ -1060,91 +1060,8 @@
 );%0A%0A
-//            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);%0A//
     
@@ -1134,31 +1134,70 @@
 er(s
-ocket.getInputStream())
+in));%0A            PrintWriter out = new PrintWriter(sout, true
 );%0A%0A
@@ -1321,13 +1321,8 @@
 line
- = %22%22
 ;%0A  
@@ -1355,20 +1355,16 @@
 rint
-ln
+f
 (%22Type 
-in 
 some
@@ -1373,83 +1373,39 @@
 ing 
-and press enter. Will
+to
  send 
-it 
 to 
-the server and tell ya what it thinks.%22
+Oracle%25s%22, SPACE
 );%0A
+%0A
     
@@ -1420,77 +1420,53 @@
     
-System.out.println();%0A%0A                while (!line.equals(%22%D0%9F%D0%BE%D0%BA%D0%B0%22)) %7B
+do %7B%0A                    String serverAnswer;
 %0A   
@@ -1546,18 +1546,17 @@
 ut.print
-ln
+f
 (%22Sendin
@@ -1583,17 +1583,26 @@
 erver...
-%22
+%25s%22, SPACE
 );%0A     
@@ -1624,64 +1624,23 @@
 out.
-writeUTF(line);%0A%0A//                    out.write
+println
 (line);%0A
     
@@ -1631,24 +1631,25 @@
 ntln(line);%0A
+%0A
             
@@ -1660,204 +1660,115 @@
     
-out.flush();%0A%0A                    line = in.readUTF();%0A//                    line = in.readLine();%0A                    System.out.println(%22The server was very polite. It sent me this : %22 + line
+serverAnswer = in.readLine();%0A                    System.out.printf(%22Server ~ %25s%22, serverAnswer + SPACE
 );%0A
+%0A
     
@@ -1783,51 +1783,38 @@
     
-    System.out.println();%0A                %7D
+%7D while (!line.equals(%22Bye%22));
 %0A   
@@ -1884,25 +1884,57 @@
 ();%0A        
-%7D
+    %7D%0A            socket.close();
 %0A        %7D c

change logic