Skip to content
Related Articles

Related Articles

java.net.SocketImplFactory Class in Java

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 25 Apr, 2022

In Java, SocketImplFactory Class is an interface java.net.SocketImplFactory Class is defining a factory for SocketImpl instances, as this interface is usable by sockets classes to create the sockets execution that implements various policies through it. Interface java.net.SocketImplFactory Class is defining the factory for setting the socketing executions. It uses classes as Socket and ServerSocket to create to its current socket executions on it.

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

java.net is one of package that use SocketImplFactory in providing the classes for executing on its networking applications. 

Method of SocketImplFactory Class

Method Action Performed
createSocketImpl() Creating an new SocketImpl instances on it

Uses of SocketImplFactory Class in java.net package 

Method Action Performed
ServerSocket.setSocketFactory(SocketImplFactory fac) Setting up an server socketing execution on factories of the application. Using an ServerSocketFactory and its subclass to ServerSocket directly.
Socket.setSocketImplFactory(SocketImplFactory fac) Setting up an client socketing executions factories of its application. Using an SocketFactory and its subclass to Socket directly.

Example 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 setted 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();
        }
    }
}


Output: 

 

Example 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 setted 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();
        }
    }
}


Output:

 

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.  


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!