Created
February 25, 2017 13:49
-
-
Save cdwijayarathna/f6e3b9d115879b8a3114e2b02587bf5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import javax.net.ssl.SSLServerSocketFactory; | |
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.net.SocketTimeoutException; | |
public class Server extends Thread | |
{ | |
private ServerSocket serverSocket; | |
public Server(int port) throws IOException | |
{ | |
SSLServerSocketFactory ssl = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); | |
serverSocket = ssl.createServerSocket(port); | |
serverSocket.setSoTimeout(100000); | |
} | |
public void run() | |
{ | |
while(true) | |
{ | |
try | |
{ | |
System.out.println("Waiting for client on port " + | |
serverSocket.getLocalPort() + "..."); | |
Socket server = serverSocket.accept(); | |
System.out.println("Just connected to " | |
+ server.getRemoteSocketAddress()); | |
DataInputStream in =new DataInputStream(server.getInputStream()); | |
System.out.println(in.readUTF()); | |
DataOutputStream out =new DataOutputStream(server.getOutputStream()); | |
out.writeUTF("Thank you for connecting to "+ server.getLocalSocketAddress() + "\nGoodbye!"); | |
server.close(); | |
}catch(SocketTimeoutException s) | |
{ | |
System.out.println("Socket timed out!"); | |
break; | |
}catch(IOException e) | |
{ | |
e.printStackTrace(); | |
break; | |
} | |
} | |
} | |
public static void main(String [] args) | |
{ | |
System.setProperty("javax.net.ssl.keyStore", "E:\\phd\\paper\\experiment\\ssl\\Server\\resources\\keystore" + | |
".jks"); | |
System.setProperty("javax.net.ssl.keyStorePassword", "accs@unsw"); | |
try | |
{ | |
Thread t = new Server(3000); | |
t.start(); | |
}catch(IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment