forked from hamzaouaddafe/AnnonceManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientTCPNotSecure.java
47 lines (39 loc) · 1.63 KB
/
ClientTCPNotSecure.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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class ClientTCPNotSecure extends ClientTCP {
public void startClient() {
System.out.println(">> start running none encrypted tcp client.");
try {
Socket socket = new Socket("localhost", 1027);
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintStream printStream = new PrintStream(socket.getOutputStream());
BufferedReader entryStream = new BufferedReader(new InputStreamReader(System.in));
String request = "";
String response = "";
printStream.println("connected");
while (!request.equalsIgnoreCase("bye")) {
response = bufferedReader.readLine();
System.out.println(
response.replace(ConsolePrinter.SEPARATOR, ConsolePrinter.BREAKER));
System.out.print(">> Commande ? : ");
request = entryStream.readLine();
printStream.println(request);
}
socket.close();
bufferedReader.close();
printStream.close();
entryStream.close();
System.out.println("Connection ended by client");
} catch (Exception e) {
System.err.println("Error in Client() : " + e.getMessage());
}
}
// /* this is client to comminucate with not secured Server */
// public static void main(String args[]) {
//
// new ClientTCPNotSecure().startClient();
// }
}