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地址. 那么,我们如果获取和 ...
随机推荐
- jQuery插件综合应用(一)注册
一.介绍 注册和登录是每个稍微有点规模的网站就应该有的功能.登陆功能与注册功能类似,也比注册功能要简单些.所以本文就以注册来说明jQuery插件的应用. jQuery插件的使用非常简单,如果只按照jQ ...
- jQuery插件综合应用(四)头像设置
一.操作流程 会员点击头像设置,弹出一个层,在层中,有上传图片的按钮,用户点击按钮上传图片,图片在服务器端按大小压缩保存(方便剪切).保存后,在前端显示,然后用户可修剪图片.选择图片区域,点击提交,保 ...
- 简易ORM(基于注解)
这是从我们现有项目做的一定的改进准备做成IDE插件 类似getter和setter的生成 1.定义实体类 通过注解说明其表名和字段名(SOURCE类型的注解 不需要运行时使用)@TableName(& ...
- WPF窗体置于桌面最底层
在WPF中设置窗体的Topmost属性可以将窗体永远置于顶部,但是没有提供Bottommost属性将窗体置底.若果要将窗体置于桌面的最底部,就需要使用Windows API来实现了.解决方案如下: 1 ...
- C#中指针使用总结
C#为了类型安全,默认并不支持指针.但是也并不是说C#不支持指针,我们可以使用unsafe关键词,开启不安全代码(unsafe code)开发模式.在不安全模式下,我们可以直接操作内存,这样就可以使用 ...
- python多线程 批量下补丁
一个一个下载 要2个多小时.就直接起了个线程池.效果明显.import urllib2 from urlparse import urlparse uri = 'http://******/patch ...
- java版 正文抽取 基于文字连接比
package cn.tdt.crawl.jdbc; import java.util.regex.Matcher; import java.util.regex.Pattern; import or ...
- Uva 1050 Ars Longa
Description You have been struck with inspiration, and are designing a beautiful new art sculpture f ...
- phpStorm 使用技巧大集合
之前整理了一部分使用技巧了,但是在实际操作中发现phpstorm的技巧实在是太多了,所以大部分都统一整理到这篇文字中 ,备用 插件1 1:phpstrom的插件Provides live edit H ...
- Android ListView中 每一项都有不同的布局
实现代码 Adapter的代码 其中:ViewHolder分别是三个不同的布局,也就是ListView中每一项的布局 TYPE_1...是三种类型. 在使用不同布局的时候,getItemViewTyp ...