ProtocolFamily 是一个 java 接口。 java.net.ProtocolFamily 代表一系列通信协议。 Java.net.StandardProtocolFamily 实现ProtocolFamily 接口。
public interface ProtocolFamily
Methods of java.net.ProtocolFamily
java.net.ProtocolFamily 接口仅包含一种方法:
编号 | 方法 | 说明 | 返回类型 |
---|---|---|---|
1. | name() | name()方法返回协议族的名称 | String |
Use of ProtocolFamily Interface
编号 | 包 | 修饰符和类型 | 姓名 | 说明 |
---|---|---|---|---|
1. | java.net | class | StandardProtocolFamily | StandardProtocolFamily 类定义通信协议的标准系列。 |
2. | java.nio.channels | 静态DatagramChannel | DatagramChannel.open(ProtocolFamily家族) | DatagramChannel.open() 静态方法打开数据报通道。 |
3. | java.nio.channels.spi | 摘要DatagramChannel | SelectorProvider.openDatagramChannel(ProtocolFamily家族) | SelectorProvider.openDatagramChannel 打开数据报通道。 |
用于更好地理解 ProtocolFamily 接口的 Java 程序
Java
// Java Program to get Protocol
// family for an IP Address
// import Guava library
import com.google.common.net.InetAddresses;
import java.io.*;
import java.net.*;
class GFG {
public static void main(String[] args)
{
try {
// to get the ip address of
InetAddress ip
= InetAddress.getByName("45.22.30.39");
System.out.println("Host Name is "
+ ip.getHostName());
// getProtocolFamily() will check and return the
// protocol family of the given IP
ProtocolFamily protocolFamily
= getProtocolFamily(ip);
System.out.println("Protocol family of the "
+ ip.getHostName() + " is "
+ protocolFamily);
}
catch (Exception e) {
System.out.println("Some exception"
+ e.getMessage());
}
}
public static ProtocolFamily
getProtocolFamily(InetAddress inetAddress)
{
// to check if address is valid or not
if (InetAddresses.isInetAddress(
inetAddress.getHostName())) {
// if address is valid
// will return the protocol family of the
// address
return StandardProtocolFamily.INET;
}
else {
// address is not valid
System.out.println(
"Address " + inetAddress
+ "is invalid hence can't determine the protocol family");
}
return StandardProtocolFamily.INET;
}
}
输出
Host Name is 45.22.30.39 Protocol family of the 45.22.30.39 is INET
相关用法
- Java java.net.Proxy用法及代码示例
- Java java.net.ProxySelector用法及代码示例
- Java java.net.PasswordAuthentication用法及代码示例
- Java java.net.SocketException用法及代码示例
- Java java.net.SocketOption用法及代码示例
- Java java.net.CookiePolicy用法及代码示例
- Java java.net.SecureCacheResponse用法及代码示例
- Java java.net.CacheResponse用法及代码示例
- Java java.net.SocketImplFactory用法及代码示例
- Java java.net.ResponseCache用法及代码示例
- Java java.net.URLPermission用法及代码示例
- Java java.net.NetPermission用法及代码示例
- Java java.net.CacheRequest用法及代码示例
- Java java.net.FileNameMap用法及代码示例
- Java java.net.CookieStore用法及代码示例
- Java java.net.CookieHandler用法及代码示例
- Java java.net.CookieManager用法及代码示例
- Java java.net.BindException用法及代码示例
- Java java.net.URLConnection用法及代码示例
- Java java.net.Socket用法及代码示例
- Java java.net.ServerSocket用法及代码示例
- Java java.net.InetAddress用法及代码示例
- Java java.nio.ByteBuffer用法及代码示例
- Java java.nio.IntBuffer用法及代码示例
- Java java.nio.file.FileStore用法及代码示例
注:本文由纯净天空筛选整理自harshsethi2000大神的英文原创作品 java.net.ProtocolFamily Class in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。