当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java java.net.SocketImplFactory用法及代码示例


在 Java 中,SocketImplFactory 类是一个接口 java.net.SocketImplFactory 类为 SocketImpl 实例定义一个工厂,因为套接字类可以使用该接口来创建通过它实现各种策略的套接字执行。接口 java.net.SocketImplFactory 类定义用于设置套接字执行的工厂。它使用 Socket 和 ServerSocket 等类来创建当前的套接字执行。

--> java.net Package
    --> SocketImplFactory Class  

java.net 是使用 SocketImplFactory 提供在其网络应用程序上执行的类的包之一。

Method of SocketImplFactory Class

方法 执行的操作
createSocketImpl() 在其上创建一个新的 SocketImpl 实例

java.net 包中SocketImplFactory 类的使用

方法 执行的操作
ServerSocket.setSocketFactory(SocketImplFactory fac) 在应用程序的工厂上设置服务器套接字执行。直接使用ServerSocketFactory及其子类ServerSocket。
Socket.setSocketImplFactory(SocketImplFactory fac) 设置其应用程序的客户端套接字执行工厂。直接使用 SocketFactory 及其子类来连接 Socket。

示例 1:

Java


// Java Program to Illustrate SocketImplFactory Class
// Method
public void Myserver java_net_SocketImplFactory() {
    // Testing for method void
    // java.net.Socket.setSocketImplFactory can not to be
    // test as settled will causes the factory to be changing
    // for all subsequent sockets
    SecurityManager sm = new SecurityManager() {
        // Method
        // To check permission
        public void checkPermission(Permission perm) {
            // Print statement
            system.out.println(
                "message= Hello GFG Readers!");
        }
        // Method
        // To check SetFactory
        public void checkSetFactory() {
             
            // Throwing SecurityExceptions
            throw new SecurityException();
        }
    }
}

输出:

示例 2:

Java


// Java Program to Illustrate SocketImplFactory Class
// Method
public void Myclient java_net_SocketImplFactory() {
    // Testing for method void method in it
    // java.net.Socket.setSocketImplFactory(java.net.SocketImplFactory)
    // Cannot to be test as settled will causing the factory
    // to be changing for all subsequent sockets
    // Accessing object of SecurityManager Class
    SecurityManager obj = new SecurityManager() {
        public void checkPermission(Permission perm) {
            system.out.println(" ");
        }
        // Checking checkSetFactory() method
        public void checkSetFactory() {
             
            // Throwing SecurityExceptions
            throw new SecurityException();
        }
    }
}

输出:

Note: In above two code we are only emphasizing on eccentric concept so do not look for the start point of execution of code as main() method is not inserted over here.  



相关用法


注:本文由纯净天空筛选整理自khurpaderushi143大神的英文原创作品 java.net.SocketImplFactory Class in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。