import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) throws IOException {
int port = 8888;
ServerSocket serverSocket = new ServerSocket(port);
System.out.println("服务器已启动,等待客户端连接...");
while (true) {
Socket socket = serverSocket.accept();
System.out.println("客户端已连接:" + socket.getInetAddress().getHostAddress());
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
String msg = in.readLine();
System.out.println("收到客户端消息:" + msg);
out.println("服务器已收到消息:" + msg);
socket.close();
}
}
}