Simple server for Secure socket : SSL Server Socket « Network Protocol « Java






Simple server for Secure socket

  

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class SSLSimpleServer extends Thread {

  public static void main(String[] args) throws Exception {
    ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(9096);

    System.out.println("Ready...");
    while (true) {
      new SSLSimpleServer(ss.accept()).start();
    }
  }

  private Socket sock;

  public SSLSimpleServer(Socket s) {
    sock = s;
  }

  public void run() {
    try {
      BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
      PrintWriter pw = new PrintWriter(sock.getOutputStream());

      String data = br.readLine();
      pw.println(data);
      pw.close();
      sock.close();
    } catch (IOException ioe) {
      // Client disconnected
    }
  }
}

           
         
    
  








Related examples in the same category

1.Creating an SSL Client Socket
2.Creating an SSL Server Socket
3.Secure Communication with JSSE
4.Secure Login based on SSL Server Socket
5.Simple Client for secure Socket
6.Secure Server
7.SSL Server Demo
8.Secure Client
9.A simple single-threaded proxy server
10.implements HandshakeCompletedListener
11.Cipher Socket