fake_world

TCPClient

Dec 6th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.Scanner;
  4.  
  5. class TCPClient{
  6.  
  7.     public static void main(String[] args) throws Exception{
  8.  
  9.         Socket sock= new Socket("127.0.0.1",4000);
  10.         System.out.println("Enter the filename");
  11.         Scanner sc = new Scanner(new InputStreamReader(System.in));
  12.         String fname= sc.nextLine();
  13.         OutputStream ostream = sock.getOutputStream();
  14.         PrintWriter pw = new PrintWriter(ostream,true);
  15.         pw.println(fname);
  16.         InputStream istream = sock.getInputStream();
  17.         Scanner sc1 = new Scanner(new InputStreamReader(istream));
  18.         String str;
  19.         while(sc1.hasNext())
  20.         {
  21.             str = sc1.nextLine();
  22.             System.out.println(str);
  23.         }
  24.         pw.close();
  25.         sock.close();
  26.         sc1.close();
  27.         sc.close();
  28.        
  29.     }
  30. }
Add Comment
Please, Sign In to add comment