KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > net > ServerSocketFactory

javax.net
Class ServerSocketFactory

java.lang.Object
  extended by javax.net.ServerSocketFactory
Direct Known Subclasses:
SSLServerSocketFactory
See Also:
Top Examples, Source Code, SocketFactory

public ServerSocket createServerSocket()
                                throws IOException
See Also:
ServerSocket.ServerSocket(), ServerSocket.bind(java.net.SocketAddress, int), ServerSocket.bind(java.net.SocketAddress)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[284]Send and receive over socket
By Anonymous on 2003/09/04 14:52:32  Rate
//The Receiver and Sender classes can readily incorporate encrypted communication through their use of socket factories. 
  
  
 import java.io.*; 
 import java.net.*; 
 import javax.net.*; 
  
  
 public class Receiver  {  
     private ServerSocketFactory factory; 
     private int port; 
     private byte [  ]  buffer; 
  
  
     public Receiver ( int port )   {  
         setPort ( port ) ; 
         setServerSocketFactory (  
             ServerSocketFactory.getDefault (  )  ) ; 
         buffer = new byte [ 2048 ] ; 
      }  
  
  
     public Receiver (  )   {  
         this ( 0 ) ; 
      }  
  
  
     public void setPort ( int port )   {  
         this.port = port; 
      }  
  
  
     public void setServerSocketFactory (  
         ServerSocketFactory factory )   {  
         this.factory = factory; 
      }  
  
  
     public void receive (  
         OutputStream out )  throws IOException  {  
         int bytes; 
         ServerSocket server; 
         Socket client; 
         InputStream in; 
  
  
         server = factory.createServerSocket ( port ) ; 
         client = server.accept (  ) ; 
         in = client.getInputStream (  ) ; 
  
  
         while (  ( bytes = in.read ( buffer )  )   > = 0 )  
             out.write ( buffer, 0, bytes ) ; 
  
  
         client.close (  ) ; 
         server.close (  ) ; 
      }  
  }  
 


public abstract ServerSocket createServerSocket(int port)
                                         throws IOException
See Also:
ServerSocket.ServerSocket(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract ServerSocket createServerSocket(int port,
                                                int backlog)
                                         throws IOException
See Also:
ServerSocket.ServerSocket(int, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract ServerSocket createServerSocket(int port,
                                                int backlog,
                                                InetAddress ifAddress)
                                         throws IOException
See Also:
ServerSocket.ServerSocket(int, int, java.net.InetAddress)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static ServerSocketFactory getDefault()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[287]Send and receive over secure socket
By Anonymous on 2003/06/26 09:23:18  Rate
//see also SocketFactory 
 //The Receive and Send programs demonstrate how SSL support can be plugged into Receiver and Sender instances. 
  
  
  
 import javax.net.*; 
 import javax.net.ssl.*; 
  
  
 public final class Receive  {  
     public static final void main ( String [  ]  args )   {  
         ServerSocketFactory factory; 
  
  
         if ( args.length != 1 && args.length != 2 )   {  
             System.err.println (  
                 "usage: Receive  [ -ssl ]  port" ) ; 
             System.exit ( 1 ) ; 
          }  
  
  
         if ( "-ssl".equals ( args [ 0 ]  )  )  
             factory = SSLServerSocketFactory.getDefault (  ) ; 
         else 
             factory = ServerSocketFactory.getDefault (  ) ; 
  
  
         try  {  
             Receiver receiver = new Receiver (  ) ; 
             int port = Integer.parseInt (  
                 args [ args.length - 1 ]  ) ; 
  
  
             receiver.setPort ( port ) ; 
             receiver.setServerSocketFactory ( factory ) ; 
             receiver.receive ( System.out ) ; 
          }  catch ( Throwable t )   {  
             t.printStackTrace (  ) ; 
             System.exit ( 1 ) ; 
          }  
      }  
  }  
  
  
 


protected ServerSocketFactory()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags