-
Notifications
You must be signed in to change notification settings - Fork 3
/
Client.java
55 lines (49 loc) · 1.55 KB
/
Client.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
45
46
47
48
49
50
51
52
53
54
55
//LEC THREE
//CLIENT-SIDE CODE FOR SERVER CLIENT COMMUNICATION
import java.io.*;
import java.net.*;
import java.util.*;
class Client {
public static void main(String[] args) {
Socket s = null;
InputStreamReader in = null;
OutputStreamWriter out = null;
BufferedReader br = null;
BufferedWriter bw = null;
try {
s = new Socket("localhost", 1234);
in = new InputStreamReader(s.getInputStream());
out = new OutputStreamWriter(s.getOutputStream());
br = new BufferedReader(in);
bw = new BufferedWriter(out);
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Msg :");
String msg = scanner.nextLine();
bw.write(msg);
bw.newLine();
bw.flush();
System.out.println("Form Server :" + br.readLine());
if (msg.equalsIgnoreCase("BYE"))
break;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (s != null)
s.close();
if (br != null)
br.close();
if (bw != null)
bw.close();
if (in != null)
in.close();
if (out != null)
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}