SSL Sockets in Java


/ Published in: Java
Save to your folder(s)

Create a Socket that uses SSL :D


Copy this code and paste it in your HTML
  1. import javax.net.ssl.*;
  2. import javax.net.*;
  3. import java.net.*;
  4. import java.io.*;
  5.  
  6.  
  7. class ...
  8.  
  9. static BufferedReader in;
  10. static BufferedWriter out;
  11. static SocketFactory sockfact;
  12. static Socket sock;
  13.  
  14.  
  15. public static ...
  16.  
  17. try {
  18.  
  19. int port = 995;
  20. String host = "pop.gmail.com";
  21. SocketFactory sockfactory = SSLSocketFactory.getDefault();
  22. Socket sock = sockfactory.createSocket(host,port);
  23. in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
  24. out = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
  25.  
  26. //Send Data
  27. out.write("data
  28. ");
  29. out.flush();
  30.  
  31. //recv Data
  32. String line = in.readLine();
  33.  
  34. }catch(Exception er) {}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.