-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
40 lines (33 loc) · 1.07 KB
/
Client.java
File metadata and controls
40 lines (33 loc) · 1.07 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
package application;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class Client {
public Client(){
Scanner scanner = new Scanner(System.in);
try {
Socket socket = new Socket("localhost",8899);
System.out.println("请在客户端输入一句话传给服务器:");
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
out.println(scanner.nextLine());
InputStreamReader isr = new InputStreamReader(socket.getInputStream());
BufferedReader in = new BufferedReader(isr);
String result = in.readLine();
System.out.println("服务器返回客户端的分词结果为:" + result);
socket.close();
} catch (UnknownHostException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public static void main(String[] args) {
Client client = new Client();
}
}