Advertisement
vencinachev

ClientDemo

Nov 23rd, 2021
809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.PrintStream;
  3. import java.net.Socket;
  4. import java.util.InputMismatchException;
  5. import java.util.Scanner;
  6.  
  7. public class ClientDemo {
  8.     public static void main(String args[]) throws IOException {
  9.         String msg;
  10.         Socket s = new Socket("127.0.0.1", 1211);
  11.         Scanner scan = new Scanner(System.in);
  12.         Scanner scan2 = new Scanner(s.getInputStream());
  13.         PrintStream printout = new PrintStream(s.getOutputStream());
  14.         System.out.print("Enter the best school name: ");
  15.         try {
  16.             msg = scan.nextLine();
  17.             printout.println(msg);
  18.             String input = scan2.nextLine();
  19.             System.out.println(input);
  20.         } catch (InputMismatchException e) {
  21.             System.out.println("Enter a correct value");
  22.         } finally {
  23.             if (s != null)
  24.                 s.close();
  25.             if (scan != null)
  26.                 scan.close();
  27.             if (scan2 != null)
  28.                 scan2.close();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement