客户端代码:
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)代码如下:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class Client {
public static void main(String[] args) {
Socket socket;
PrintStream ps;
try {
socket = new Socket("127.0.0.1",1111);
System.out.println("connect successfully...");
System.out.println("Please input some WORDS to server:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String content = null;
try {
content = br.readLine();
} catch (Exception e) {
}
ps = new PrintStream(socket.getOutputStream(),true,"UTF-8");
ps.print(content);
socket.close();
} catch (Exception e) {
System.out.println(e);
}
}
}