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地址. 那么,我们如果获取和 ...
随机推荐
- zTree的getChangeCheckedNodes()使用
zTree的getChangeCheckedNodes()方法用于获取输入框勾选状态被改变的节点集合.如果需要获取每次操作后全部被改变勾选状态的节点数据,请在每次勾选操作后,遍历所有被改变勾选状态的节 ...
- JavaScript学习总结【12】、JS AJAX应用
1.AJAX 简介 AJAX(音译为:阿贾克斯) = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML),是指一种创建交互式网页应用的网页开发技 ...
- CentOS6.4 使用谷歌Chromium浏览器
那么,如果希望在CentOS/RHEL 7出来之前继续使用Chrome怎么办?使用Chrome的开源版本:Chromium. 1.切换到root: su - 或者 sudo -i 2.下载新的软件源定 ...
- C++相关资源
http://www.cnblogs.com/xi52qian/p/4186983.html语言ISO/IEC JTC1/SC22/WG21 - The C++ Standards Committee ...
- 推送 -- error:Not get deviceToken yet
获取不到devicetoken请检查: 1) 请检查你的pushconfig里的appkey与应用详情中是否一致 2) bundleid有3处需要检查是否一致:a.你的应用详情中的bu ...
- iOS中使用RegexKitLite来试用正则表达式 使用ARC 20个错误解决办法
You can also disable the ARC for the RegexKitLite only by adding a flag: select the project -> YO ...
- 移动App双周版本迭代实战--转载备用
对于移动互联网产品来说,迭代的速度就是生命.我创业时做移动App时是一周一版,而现在是2周1版.相比起小公司,大公司迭代时间虽长,却更为不易,因为大公司流程更多,参与人数更多,需求更多,实现这样的快速 ...
- C++ QT中的QSound使用方法
在pro文件中添加 QT += multimedia 就可以了
- 注解方式传LIST@RequestBody
在SpringMVC中使用注解方式传List类型的参数时,要使用@RequestBody注解而不是@RequestParam注解 //创建文件夹 @RequestMapping(value=" ...
- adb logcat 查看日志
使用 logcat 命令 查看和跟踪系统日志缓冲区的命令logcat的一般用法是: [adb] logcat [<option>] ... [<filter-spec>] .. ...