Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.Scanner;
- class TCPClient{
- public static void main(String[] args) throws Exception{
- Socket sock= new Socket("127.0.0.1",4000);
- System.out.println("Enter the filename");
- Scanner sc = new Scanner(new InputStreamReader(System.in));
- String fname= sc.nextLine();
- OutputStream ostream = sock.getOutputStream();
- PrintWriter pw = new PrintWriter(ostream,true);
- pw.println(fname);
- InputStream istream = sock.getInputStream();
- Scanner sc1 = new Scanner(new InputStreamReader(istream));
- String str;
- while(sc1.hasNext())
- {
- str = sc1.nextLine();
- System.out.println(str);
- }
- pw.close();
- sock.close();
- sc1.close();
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment