-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientsServer.java
More file actions
67 lines (63 loc) · 2.27 KB
/
ClientsServer.java
File metadata and controls
67 lines (63 loc) · 2.27 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
package Network;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ReverseEchoServer {
public static void main(String[] args) {
try {
ServerSocket SS = new ServerSocket(2000);
Socket SK = SS.accept();
BufferedReader KB = new BufferedReader(new InputStreamReader(System.in));
BufferedReader BR = new BufferedReader(new InputStreamReader(SK.getInputStream()));
System.out.println("\nConnected to Client");
System.out.println("Waiting for Message");
PrintStream PS = new PrintStream(SK.getOutputStream());
String MSG = "";
StringBuilder SB;
while (!MSG.equals("exit")){
MSG = BR.readLine();
System.out.println("From Client: "+MSG);
// SB = new StringBuilder(MSG);
// SB.reverse();
// MSG = SB.toString();
if(MSG.equals("exit"))
System.exit(0);
System.out.print("Reply to Client: ");
MSG = KB.readLine();
PS.println(MSG);
}
SK.close();
SS.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
class Client {
public static void main(String[] args) {
try {
Socket SK = new Socket("192.168.53.198",2000);
BufferedReader KB = new BufferedReader(new InputStreamReader(System.in));
BufferedReader BR = new BufferedReader(new InputStreamReader(SK.getInputStream()));
System.out.println("\nConnected to Server");
PrintStream PS = new PrintStream(SK.getOutputStream());
String MSG = "";
while(!MSG.equals("exit")){
System.out.print("Send Message to Server: ");
MSG = KB.readLine();
PS.println(MSG);
if(MSG.equals("exit"))
System.exit(0);
MSG = BR.readLine();
System.out.println("From Server: "+MSG);
}
SK.close();
}
catch(Exception e){
System.out.println(e);
}
}
}