Advertisement
Guest User

let's do it

a guest
Feb 21st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3.  
  4. public class MyClient{
  5.  
  6.  
  7.     public static void main(String[] args) throws IOException{
  8.  
  9.         String hostname = "localhost";
  10.  
  11.         int port = Integer.parseInt(args[0]);
  12.  
  13.     while(true){
  14.  
  15.  
  16.         try(Socket  socket = new Socket(hostname ,port)){
  17.  
  18.  
  19.             System.out.println("Connected!");
  20.  
  21.             InputStream input = socket.getInputStream();
  22.  
  23.             BufferedReader reader = new BufferedReader( new InputStreamReader(input));
  24.  
  25.             String data = reader.readLine();
  26.  
  27.             System.out.println(data);
  28.  
  29.  
  30.         }
  31.         catch(IOException e){
  32.  
  33.            System.out.println(e);
  34.         }
  35.  
  36.         }
  37.  
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement