[java]代码库
import java.net.*;
02 import java.io.*;
03
04 public class Client {
05 static Socket server;
06
07 public static void main(String[] args) throws Exception {
08 server = new Socket(InetAddress.getLocalHost(), 9999); // 使用9999端口
09 BufferedReader in = new BufferedReader(new InputStreamReader(
10 server.getInputStream()));
11 PrintWriter out = new PrintWriter(server.getOutputStream());
12 BufferedReader wt = new BufferedReader(new InputStreamReader(System.in));
13
14 while (true) {
15 String str = wt.readLine();
16 out.println(str);
17 out.flush();
18 if (str.equals("end")) {
19 break;
20 }
21 System.out.println(in.readLine());
22 }
23 server.close();
24 }
25 }