Skip to content

Instantly share code, notes, and snippets.

@tekbird
Last active November 14, 2018 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekbird/4556302f7d03b98c781c0e31be501b6c to your computer and use it in GitHub Desktop.
Save tekbird/4556302f7d03b98c781c0e31be501b6c to your computer and use it in GitHub Desktop.
java ssl socket server
public static void main(String[] args) throws IOException {
System.setProperty("javax.net.ssl.keyStore", "C:\\path\\to\\keystore\\store.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "Password1");
SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
ServerSocket ss = ssf.createServerSocket(7000);
System.out.println("started");
while (true) {
Socket s = ss.accept();
System.out.println("connected");
InputStreamReader reader = new InputStreamReader(s.getInputStream());
char[] chars = new char[10];
reader.read(chars);
System.out.println(new String(chars));
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment