Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 4th, 2020 934 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Server {
  3.     public static void main(String[] args) {
  4.         int port = 8080;
  5.  
  6.         try (ServerSocket serverSocket = new ServerSocket(port)) {
  7.  
  8.             System.out.println("Server is listening on port " + port);
  9.  
  10.             while (true) {
  11.                 Socket socket = serverSocket.accept();
  12.                 System.out.println("New client connected");
  13.  
  14.                 InputStream input = socket.getInputStream();
  15.                 BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  16.  
  17.                 OutputStream output = socket.getOutputStream();
  18.                 PrintWriter writer = new PrintWriter(output, true);
  19.  
  20.  
  21.                 String text;
  22.  
  23.                 do {
  24.                     text = reader.readLine();
  25.                     String reverseText = new StringBuilder(text).reverse().toString();
  26.                     writer.println("Server: " + reverseText);
  27.  
  28.                 } while (!text.equals("bye"));
  29.  
  30.                 socket.close();
  31.             }
  32.  
  33.         } catch (IOException ex) {
  34.             System.out.println("Server exception: " + ex.getMessage());
  35.             ex.printStackTrace();
  36.         }
  37.     }
  38. }
  39.  
  40. public class Client {
  41.     public static void main(String[] args) {
  42.         String hostname = "localhost";
  43.         int port = 8080;
  44.         try (Socket socket = new Socket(hostname, port)) {
  45.  
  46.             OutputStream output = socket.getOutputStream();
  47.             PrintWriter writer = new PrintWriter(output, true);
  48.  
  49.             Console console = System.console();
  50.             String text;
  51.  
  52.             do {
  53.                 text = console.readLine("Enter text: "); // Эта строчка NPO
  54.  
  55.                 writer.println(text);
  56.  
  57.                 InputStream input = socket.getInputStream();
  58.                 BufferedReader reader = new BufferedReader(new InputStreamReader(input));
  59.  
  60.                 String time = reader.readLine();
  61.  
  62.                 System.out.println(time);
  63.  
  64.             } while (!text.equals("bye"));
  65.  
  66.         } catch (UnknownHostException ex) {
  67.  
  68.             System.out.println("Server not found: " + ex.getMessage());
  69.  
  70.         } catch (IOException ex) {
  71.  
  72.             System.out.println("I/O error: " + ex.getMessage());
  73.         }
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top