简体   繁体   English

了解 InetAddress

[英]Understanding InetAddress

I have this code.It works fine.But I don't understand the meaning of few lines of code.I have written comments next to lines I'm unable to understand.Can anyone please help me with understanding these lines.Thanks in advance :)我有这个代码。它工作正常。但我不明白几行代码的含义。我在我无法理解的行旁边写了注释。任何人都可以帮助我理解这些行。提前致谢:)

import java.net.InetAddress;

public class Netaddress
{
    public static void main(String a[]) throws Exception
      {
          InetAddress c;      //this line
          c =InetAddress.getLocalHost();   //and this one
          System.out.println("Local Address Is :"+c);
          System.out.println("Done!");
      }
}

InetAddress is a class in Java (java.net package). InetAddress是 Java 中的一个类(java.net 包)。 From the javadoc of getLocalHost ( emphasis mine )来自getLocalHost的 javadoc(重点是我的

Returns the address of the local host .返回本地主机地址 This is achieved by retrieving the name of the host from the system, then resolving that name into an InetAddress.这是通过从系统检索主机的名称,然后将该名称解析为 InetAddress 来实现的。 Note: The resolved address may be cached for a short period of time.注意:解析后的地址可能会被缓存一小段时间。

If there is a security manager, its checkConnect method is called with the local host name and -1 as its arguments to see if the operation is allowed.如果存在安全管理器,则使用本地主机名和 -1 作为参数调用其 checkConnect 方法,以查看是否允许操作。 If the operation is not allowed, an InetAddress representing the loopback address is returned.如果不允许该操作,则返回表示环回地址的 InetAddress。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM