[java]代码库import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class Main {
private static final int PORT = 9999;
public static void main(String[] args) {
try {
// 实例化服务器套接字 设置端口号9999
ServerSocket server = new ServerSocket(PORT);
while (true) {
Socket socket = server.accept();
// 获取输出流
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream()));
// 写字符串
writer.write("这是一段来自服务器的问候:Hello");
writer.flush();
writer.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}