The InetAddress is Java's representation of an IP address. Instances of this class are used together with UDP DatagramSockets and normal Socket's and ServerSocket's.

Creating an InetAddress Instance

InetAddress has no public contructor, so you must obtain instances via a set of static methods.

Here is how to get the InetAddress instance for a domain name:

InetAddress address = InetAddress.getByName("jenkov.com");

And here is how to get the InetAddress matching a String representation of an IP address:

InetAddress address = InetAddress.getByName("78.46.84.171");

And, here is how to obtain the IP address of the localhost (the computer the program is running on):

InetAddress address = InetAddress.getLocalHost();

Additional InetAddress Methods

The InetAddress class has a lot of additional methods you can use. For instance, you can obtain the IP address as a byte array by calling getAddress() etc. To learn more about these methods, it is easier to read the JavaDoc for the InetAddress class though.

Java Networking: InetAddress的更多相关文章

  1. Java Networking: UDP DatagramSocket (翻译)

    原文:http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html UDP vs. TCP Sending Data vi ...

  2. java中Inetaddress类

    InetAddress类 InetAddress类用来封装我们前面讨论的数字式的IP地址和该地址的域名. 你通过一个IP主机名与这个类发生作用,IP主机名比它的IP地址用起来更简便更容易理解. Ine ...

  3. [已解决] java.net.InetAddress.getHostName() 阻塞问题

    在学习java nio的过程中发现某些情况下使用该方法会导致程序阻塞,(情况:服务器,Linux:客户端,WIN10) java.net.InetAddress.getHostName() 阻塞情况如 ...

  4. Android(java)学习笔记79:java中InetAddress类概述和使用

    要想让网络中的计算机能够互相通信,必须为每台计算机指定一个标识号,通过这个标识号来指定要接受数据的计算机和识别发送的计算机. 在TCP/IP协议中,这个标识号就是IP地址. 那么,我们如果获取和操作I ...

  5. (Java学习笔记) Java Networking (Java 网络)

    Java Networking (Java 网络) 1. 网络通信协议 Network Communication Protocols Network Protocol is a set of rul ...

  6. at java.net.InetAddress.getLocalHost(InetAddress.java:1475)

    今天在centos 安装hadoop安装完成后执行wordcount的时候报如下错误: at java.net.InetAddress.getLocalHost(InetAddress.java:14 ...

  7. IP和java.net.InetAddress类的使用

    一.IP 1.地址格式 互联网上每一台计算机都有一个唯一标示自己的标记,这个标记就是IP地址.IP 地址使用32 位长度二进制数据标示,一般在实际中看到的大部分IP地址都是以十进制的数据形式标示的,如 ...

  8. Java学习---InetAddress类的学习

    基础知识 1.InetAddress类 在网络API套接字,InetAddress类和它的子类型对象使用域名DNS系统,处理主机名到主机IPv4或IPv6地址的转换.如图1-1所示. 由于InetAd ...

  9. Android(java)学习笔记19:Java中InetAddress类概述和使用

    1. 要想让网络中的计算机能够互相通信,必须为每台计算机指定一个标识号,通过这个标识号来指定要接受数据的计算机和识别发送的计算机. 在TCP/IP协议中,这个标识号就是IP地址. 那么,我们如果获取和 ...

随机推荐

  1. php错误捕捉

    <?php //禁止错误输出 error_reporting(0); //设置错误处理器 set_error_handler('errorHandler'); register_shutdown ...

  2. Python使用re实现计算器

    re 正则表达式 计算器 海瑞博客-学习python之路•2016-12-01•Python• 59•0•A+ A- re是一门小型语言 元字符 .      通配符除了\n ^     以什么开始的 ...

  3. sql性能优化总结(转)

    网上看到一篇sql优化的文章,整理了一下,发现很不错,虽然知道其中的部分,但是没有这么全面的总结分析过…… 一.   目的 数据库参数进行优化所获得的性能提升全部加起来只占数据库应用系统性能提升的40 ...

  4. bounds的深入研究

    一.bounds的深入研究 1>frame:是以父控件的左上角为原点,描述的是一块区域的可视范围,    bounds:是以自己内容左上角为原点,描述的是可视范围在内容范围显示的区域 2> ...

  5. 发布FireBird数据库所需要DLL文件

    数据库版本:2.5.2 ib_util.dll; icudt30.dll; icuin30.dll icuuc30.dll

  6. Word图片显示不完整

    选中图片和上下文字,段落里选择单倍行距,其他行距不行.

  7. CF 33B String Problem

    对每个位置进行操作,求出最终变成相同字母的代价,然后把所有的位上代价加起来,使得总代价最小.res[i][j]表示将字母i+'a'和字母j+'a'变为相同的代价,设最终都变成字母k+'a',那么res ...

  8. [wikioi]拦截导弹

    http://wikioi.com/problem/1044/ 这道题是DP.前一问很自然可以规约成最长不升(含等号下降)子序列.难点在后一问为何能规约成最长上升子序列.后来看了网上的回答,仍然没有简 ...

  9. 读书笔记-----Java并发编程实战(二)对象的共享

    public class NoVisibility{ private static boolean ready; private static int number; private static c ...

  10. Jquery 获取表单值如input,select等方法

    1 if($("input[name=item][value='val']").attr('checked')==true) //判断是否已经打勾 name即控件name属性,va ...