2021-10-09 网络编程(浏览器客户端-自定义服务端)
2021-11-04 本文已影响0人
Denholm
演示客户端和服务端
客户端:浏览器
服务端:自定义
telnet
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerDemo {
public static void main(String[] args) throws Exception {
ServerSocket server = new ServerSocket(11000);
Socket accept = server.accept();
System.out.println(accept.getInetAddress().getHostAddress());
PrintWriter out = new PrintWriter(accept.getOutputStream(), true);
out.println("<font color='red size='7'>客户端你好</font>");
accept.close();
server.close();
}
}