From 03c8767c8559b058bda777fc37c02b5fdd966f86 Mon Sep 17 00:00:00 2001 From: Nicol Radwan Date: Sun, 5 Jan 2020 20:28:21 +0000 Subject: [PATCH] Zaktualizuj 'Client.java' --- Client.java | 168 ++++++++++++++++++++++++++-------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/Client.java b/Client.java index 87d8034..96f9a2d 100644 --- a/Client.java +++ b/Client.java @@ -1,84 +1,84 @@ -import java.net.*; -import java.io.*; - -public class Client -{ - public static void main(String args[]) - { - //pobranie i sprawdzenie otrzymanych argumentów - if (args.length < 2){ - System.out.println("Wywołanie programu: Client host port"); - System.exit(-1); - } - String host = args[0]; - int port = 0; - try{ - port = Integer.valueOf(args[1]); - } - catch(NumberFormatException e){ - System.out.println("Nieprawidłowy argument: port"); - System.exit(-1); - } - //Inicjalizacja gniazda klienckiego - Socket clientSocket = null; - try{ - clientSocket = new Socket(host, port); - } - catch(UnknownHostException e){ - System.out.println("Nieznany host."); - System.exit(-1); - } - catch(ConnectException e){ - System.out.println("Połączenie odrzucone."); - System.exit(-1); - } - catch(IOException e){ - System.out.println("Błąd wejścia-wyjścia: " + e); - System.exit(-1); - } - System.out.println("Połączono z " + clientSocket); - - //Deklaracje zmiennych strumieniowych - String line = null; - BufferedReader brSockInp = null; - BufferedReader brLocalInp = null; - DataOutputStream out = null; - - //Utworzenie strumieni - try{ - out = new DataOutputStream(clientSocket.getOutputStream()); - brSockInp = new BufferedReader( - new InputStreamReader( - clientSocket.getInputStream())); - brLocalInp = new BufferedReader( - new InputStreamReader(System.in)); - } - catch(IOException e){ - System.out.println("Błąd przy tworzeniu strumieni: " + e); - System.exit(-1); - } - //Pętla główna klienta - while(true){ - try{ - line = brLocalInp.readLine(); - if(line != null){ - System.out.println("Wysyłam: " + line); - out.writeBytes(line + '\n'); - out.flush(); - } - if(line == null || "quit".equals(line)){ - System.out.println("Kończenie pracy..."); - clientSocket.close(); - System.exit(0); - } - brSockInp.readLine(); - System.out.println("Otrzymano: " + line); - } - catch(IOException e){ - System.out.println("Błąd wejścia-wyjścia: " + e); - System.exit(-1); - } - } - } -} - +import java.net.*; +import java.io.*; + +public class Client +{ + public static void main(String args[]) + { + //pobranie i sprawdzenie otrzymanych argumentĂłw + if (args.length < 2){ + System.out.println("WywoĹ‚nie programu: Client host port"); + System.exit(-1); + } + String host = args[0]; + int port = 0; + try{ + port = Integer.valueOf(args[1]); + } + catch(NumberFormatException e){ + System.out.println("NieprawidĹ‚owy argument: port"); + System.exit(-1); + } + //Inicjalizacja gniazda klienckiego + Socket clientSocket = null; + try{ + clientSocket = new Socket(host, port); + } + catch(UnknownHostException e){ + System.out.println("Nieznany host."); + System.exit(-1); + } + catch(ConnectException e){ + System.out.println("PoĹ‚Ä…czenie odrzucone."); + System.exit(-1); + } + catch(IOException e){ + System.out.println("BĹ‚Ä…d wejĹ›cia-wyjĹ›cia: " + e); + System.exit(-1); + } + System.out.println("PoĹ‚Ä…czono z " + clientSocket); + + //Deklaracje zmiennych strumieniowych + String line = null; + BufferedReader brSockInp = null; + BufferedReader brLocalInp = null; + DataOutputStream out = null; + + //Utworzenie strumieni + try{ + out = new DataOutputStream(clientSocket.getOutputStream()); + brSockInp = new BufferedReader( + new InputStreamReader( + clientSocket.getInputStream())); + brLocalInp = new BufferedReader( + new InputStreamReader(System.in)); + } + catch(IOException e){ + System.out.println("BĹ‚Ä…d przy tworzeniu strumieni: " + e); + System.exit(-1); + } + //PÄ™tla gĹ‚Ăłwna klienta + while(true){ + try{ + line = brLocalInp.readLine(); + if(line != null){ + System.out.println("WysyĹ‚am: " + line); + out.writeBytes(line + '\n'); + out.flush(); + } + if(line == null || "quit".equals(line)){ + System.out.println("KoĹ„czenie pracy..."); + clientSocket.close(); + System.exit(0); + } + brSockInp.readLine(); + System.out.println("Otrzymano: " + line); + } + catch(IOException e){ + System.out.println("BĹ‚Ä…d wejĹ›cia-wyjĹ›cia: " + e); + System.exit(-1); + } + } + } +} +