为什么以下代码将电子邮件地址用作主机名?

时间:2019-07-09 15:27:11

标签: java sockets

此刻,我正在学习有关套接字的知识,并以创建手指客户端为例。我注意到主机名应该是电子邮件地址,而不是以下代码中的域名:

import java.io.*;
import java.net.*;
import java.util.*;

public class Finger {
    public static void main(String[] args) {
        String user;
        String host;
        if ((args.length == 1) && (args[0].indexOf("@") > -1)) {
            StringTokenizer split = new StringTokenizer(args[0],
                "@");
            user = split.nextToken();
            host = split.nextToken();
        } else {
            System.out.println("Usage: java Finger user@host");
            return;
        }
        try (Socket digit = new Socket(host, 79);
            BufferedReader in = new BufferedReader(
                new InputStreamReader(digit.getInputStream()));
            ) {

            digit.setSoTimeout(20000);
            PrintStream out = new PrintStream(
                digit.getOutputStream());
            out.print(user + "\015\012");

            boolean eof = false;
            while (!eof) {
                String line = in.readLine();
                if (line != null) {
                    System.out.println(line);
                } else {
                    eof = true;
                }
            }
            digit.close();
        } catch (IOException e) {
            System.out.println("IO Error:" + e.getMessage());
        }
    }
}

这不是域名吗,因为电子邮件地址用于解析电子邮件服务器而非手指服务器的IP?

0 个答案:

没有答案