-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathClient.java
31 lines (27 loc) · 1.01 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public class Client {
public static void main(String[] args) {
try(Socket socket = new Socket("localhost",5000)){
BufferedReader iStream = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter oStream = new PrintWriter(socket.getOutputStream(),true);
Scanner scanner = new Scanner(System.in);
while(true){
System.out.print("input> ");
String message = scanner.nextLine();
oStream.println(message);
if(message.equalsIgnoreCase("exit")){
String response = iStream.readLine();
System.out.println(response);
break;
}
}
}catch (Exception e){
System.out.println("error: "+e.getMessage());
}
}
}