-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-TCPC.java
44 lines (34 loc) · 917 Bytes
/
4-TCPC.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
import java.net.*;
import java.io.*;
public class TCPC{
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(System.in);
String fname=sc.nextLine();
OutputStream ostream=sock.getOutputStream();
PrintWriter pwrite=new PrintWriter(ostream,true);
pwrite.println(fname);
InputStream istream=sock.getInputStream();
BufferedReader socketRead=new BufferedReader(new InputStreamReader(istream));
String str;
while((str=socketRead.readLine())!=null){
System.out.println(str);
}
sock.close();
socketRead.close();
pwrite.close();
}
}
/*
Output:
$ java TCPS
Server is ready for connection
Connection is established and server is waiting for client request
Client request fulfilled
$ java TCPC
Enter the filename
sample.txt
You are genius
*/