forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmclient.java
43 lines (39 loc) · 1.29 KB
/
mclient.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
import java.util.*;
import java.net.*;
import java.io.*;
public class mclient {
public static void main(String s[]) throws Exception {
Socket s1 = null;
String line = null;
DataInputStream br = null;
DataInputStream is = null;
PrintWriter os = null;
try {
s1 = new Socket("localhost", 9999);
br = new DataInputStream(System.in);
is = new DataInputStream(s1.getInputStream());
os = new PrintWriter(s1.getOutputStream());
} catch (IOException e) {
System.err.print("IO Exception");
}
System.out.println("Enter data to server (enter QUIT to end) :-> "+s1.getRemoteSocketAddress().toString());
String res = null;
try {
line = br.readLine();
while (line.compareTo("QUIT") != 0) {
os.println(line);
os.flush();
res = is.readLine();
System.out.println("server response :-> " + res);
line = br.readLine();
}
is.close();
os.close();
br.close();
s1.close();
System.out.println("close connection ");
} catch (IOException e) {
System.out.println("socket read error");
}
}
}