Java Networking: InetAddress
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的更多相关文章
- Java Networking: UDP DatagramSocket (翻译)
原文:http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html UDP vs. TCP Sending Data vi ...
- java中Inetaddress类
InetAddress类 InetAddress类用来封装我们前面讨论的数字式的IP地址和该地址的域名. 你通过一个IP主机名与这个类发生作用,IP主机名比它的IP地址用起来更简便更容易理解. Ine ...
- [已解决] java.net.InetAddress.getHostName() 阻塞问题
在学习java nio的过程中发现某些情况下使用该方法会导致程序阻塞,(情况:服务器,Linux:客户端,WIN10) java.net.InetAddress.getHostName() 阻塞情况如 ...
- Android(java)学习笔记79:java中InetAddress类概述和使用
要想让网络中的计算机能够互相通信,必须为每台计算机指定一个标识号,通过这个标识号来指定要接受数据的计算机和识别发送的计算机. 在TCP/IP协议中,这个标识号就是IP地址. 那么,我们如果获取和操作I ...
- (Java学习笔记) Java Networking (Java 网络)
Java Networking (Java 网络) 1. 网络通信协议 Network Communication Protocols Network Protocol is a set of rul ...
- at java.net.InetAddress.getLocalHost(InetAddress.java:1475)
今天在centos 安装hadoop安装完成后执行wordcount的时候报如下错误: at java.net.InetAddress.getLocalHost(InetAddress.java:14 ...
- IP和java.net.InetAddress类的使用
一.IP 1.地址格式 互联网上每一台计算机都有一个唯一标示自己的标记,这个标记就是IP地址.IP 地址使用32 位长度二进制数据标示,一般在实际中看到的大部分IP地址都是以十进制的数据形式标示的,如 ...
- Java学习---InetAddress类的学习
基础知识 1.InetAddress类 在网络API套接字,InetAddress类和它的子类型对象使用域名DNS系统,处理主机名到主机IPv4或IPv6地址的转换.如图1-1所示. 由于InetAd ...
- Android(java)学习笔记19:Java中InetAddress类概述和使用
1. 要想让网络中的计算机能够互相通信,必须为每台计算机指定一个标识号,通过这个标识号来指定要接受数据的计算机和识别发送的计算机. 在TCP/IP协议中,这个标识号就是IP地址. 那么,我们如果获取和 ...
随机推荐
- @using (Html.BeginForm())收集
一 ,制定表单提交方式和路径 1,指明(视图,控制器,提交方式,参数) <%using(Html.BeginForm("Index","Home",For ...
- 【转】Spring事务管理
原文链接 在 Spring 中,事务是通过 TransactionDefinition 接口来定义的.该接口包含与事务属性有关的方法.具体如清单 1 所示: 清单 1. TransactionDefi ...
- OpenCart框架运行流程介绍
框架运行流程介绍 这样的一个get请求http://hostname/index.php?route=common/home 发生了什么? 1. 开始执行入口文件index.php. 2. requi ...
- C语言-07其它相关
预处理指令 /* 不带参数的宏定义 1.所有的预处理指令都是以#开头 2.预处理指令分3种 1> 宏定义 2> 条件编译 3> 文件包含 3.预处理指令在代码翻译成0和1之前执行 4 ...
- android中LayoutInflater详解与使用
android的LayoutInflater用来得到一个布局文件,也就是xxx.xml,而我们常用的findviewbyid是用来取得布局文件里的控件或都布局.inflater即为填充的意思,也就是说 ...
- 【python之路7】python基本数据类型(一)
一.运算符 1.算数运算符 +.-.*./.%(求余数).//(取整数部分) python2.x中,如果计算浮点数其中一个数字必须是浮点数否则按整数计算: 如python2.7中:print 9/2 ...
- UM分享 - 详解
官网: http://dev.umeng.com 友盟现在发展的很壮大! 有熟为人知的社会化分享\统计分析\消息推送\即时通信\自动更新\多媒体服务等功能, 今天就其中第一项 分享功能, 做出分解. ...
- WebService学习整理(一)——客户端三种调用方式整理
1 WebService基础 1.1 作用 1, WebService是两个系统的远程调用,使两个系统进行数据交互,如应用: 天气预报服务.银行ATM取款.使用邮箱账号登录各网站等. 2, ...
- avalon中require的实现
var plugins = { loader: function(builtin) { window.define = builtin ? innerRequire.define : otherDef ...
- 无法修改系统Host的解决办法
有些时候可能因为杀毒软件的问题,即使打开隐藏文件也是无法正常看到hosts的. 此时可以新建一个hosts文件去覆盖目录下的文件即可见 路径:C:\Windows\System32\drivers\e ...