-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEchoClient.java
More file actions
29 lines (27 loc) · 930 Bytes
/
EchoClient.java
File metadata and controls
29 lines (27 loc) · 930 Bytes
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
//Ben Chin
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintStream;
public final class EchoClient {
public static void main(String[] args) throws Exception {
try (Socket socket = new Socket("localhost", 22222)) {
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(isr);
Scanner kb = new Scanner(System.in);
OutputStream os = socket.getOutputStream();
PrintStream out = new PrintStream(os);
System.out.print("Client> ");
String message;
while(!(message = kb.nextLine()).equals("exit")){
out.println(message);
System.out.println("Server> " + br.readLine());
System.out.print("Client> ");
}
}
}
}