KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > net > ssl > SSLServerSocketFactory

javax.net.ssl
Class SSLServerSocketFactory

java.lang.Object
  extended by javax.net.ServerSocketFactory
      extended by javax.net.ssl.SSLServerSocketFactory
See Also:
Top Examples, Source Code, SSLSocket, SSLServerSocket

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


[237]Sets up an SSL socket to securely communicate with a Web server, using the HTTPS protocol
By Anonymous on 2003/04/25 14:42:26  Rate
//The following code sets up an SSL socket to securely communicate with a Web server, using the HTTPS protocol: 
  
  
  
 import javax.net.ssl.*; 
 import java.io.*; 
    
 // Get a SocketFactory object for creating SSL sockets 
 SSLSocketFactory factory =  ( SSLSocketFactory )  SSLSocketFactory.getDefault (  ) ; 
  
  
 // Create a secure socket connected to the HTTPS port  ( port 443 )  of a server 
 SSLSocket sslsock =  ( SSLSocket )  factory.createSocket ( hostname, 443 ) ; 
  
  
 // Get the certificate presented by the web server. This may throw an  
 // exception if the server didn't supply a certificate. Look at the 
 // issuer of the certificate and decide if it is trusted. 
 SSLSession session = sslsock.getSession (  ) ; 
 X509Certificate cert =  ( X509Certificate ) session.getPeerCertificates (  )  [ 0 ] ; 
 String issuer = cert.getIssuerDN (  ) .getName (  ) ;  
  
  
 // Assuming we trust the certificate, we now use the socket just like a normal 
 // java.net.Socket object. So send a HTTP request and read the response 
 PrintWriter out = new PrintWriter ( sslsock.getOutputStream (  )  ) ; 
 out.print ( "GET " + args [ 1 ]  + " HTTP/1.0\r\n\r\n" ) ; 
 out.flush (  ) ; 
  
  
 // Next, read the server's response and print it to the console. 
 BufferedReader in = 
   new BufferedReader ( new InputStreamReader ( sslsock.getInputStream (  )  )  ) ; 
 String line; 
 while (  ( line = in.readLine (  )  )  != null )  System.out.println ( line ) ; 
  
  
 // Finally, close the socket. 
 sslsock.close (  ) ;  
  
  
 


public abstract String[] getDefaultCipherSuites()
See Also:
getSupportedCipherSuites()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract String[] getSupportedCipherSuites()
See Also:
getDefaultCipherSuites()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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

Popular Tags