如何使用Java监听17、'qotd'端口?

How to use Java to listen to port 17, 'qotd'?

问题是我只找到了关于端口 17 的一些描述,也称为 "Quote of the date" 端口。无用的端口,除了显示少于 512 个 ASCII 字符的引号外什么都不做。有人可以给我更多关于如何在 Java 中监听端口 17 的信息吗?我已经使用 port:6017.

建立了一个服务器客户端套接字

代码如下:

public class DateServer {
    public static void main(String[] args) {
        try {
            ServerSocket sock = new ServerSocket(6017);

            // now listen for connections
            while (true) {
                Socket client = sock.accept();
                // we have a connection

                PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
                // write the Date to the socket
                pout.println(); // I know something must happens here!!!

                // close the socket and resume listening for more connections
                client.close();
            }
        } catch (IOException ioe) {
            System.err.println(ioe);
        }
    }
}

系统运行在Linux,这段代码是程序的服务器端。我正在处理客户端部分,并尝试让服务器执行与端口 17 相同的操作,然后让客户端从服务器接收 "quote of the day"。

小于 1024 的端口是特权端口,需要升级到 运行 的权限。 运行 您的程序作为您计算机的管理员,端口设置为 17。