Wiki Markup |
---|
As suggested by \[[Ware|AA. Java References#Ware 08]\], instances from the class javax.net.ssl.SSLSocket should be created instead of normal Sockets when transferring objects over communication channels. SSLSockets provide a layer of security protocols such as SSL or TLS. |
According to Java API 1.4.2, the principal protections included in SSLSockets that are not provided by the Socket class are:
...
Code Block |
---|
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import java.io.*; public class EchoClient { public static void main(String[] args) { try { SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("localhost", 9999); PrintWriter out = new PrintWriter(sslsocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(sslsocket.getInputStream())); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println(in.readLine()); } out.close(); in.close(); stdIn.close(); sslsocket.close(); } catch (Exception e) { /*Handle exception*/ } } } |
References
Wiki Markup |
---|
\[[Ware 08|AA. Java References#Ware 08]\] |