Methods Summary |
---|
protected void | buildGUI()
JPanel newContentPane = new JPanel(new BorderLayout());
newContentPane.add(buildMainPanel(), BorderLayout.CENTER);
setContentPane(newContentPane);
setSize(250, 300);
|
private javax.swing.JComponent | buildMainPanel()
_displayArea = new JTextArea();
_displayArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(_displayArea);
scrollPane.setBorder(new EtchedBorder());
return scrollPane;
|
private java.net.ServerSocket | getSSLServerSocket(int port)
SSLServerSocketFactory socketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
SSLServerSocket returnValue = (SSLServerSocket) socketFactory.createServerSocket(port);
returnValue.setEnabledCipherSuites(CIPHERS);
returnValue.setNeedClientAuth(false);
returnValue.setEnableSessionCreation(true);
return returnValue;
|
private void | processClientRequest(java.net.Socket client)
_displayArea.append("Client connected from port " +
client.getPort() + " on machine " + client.getInetAddress() + "\n");
_displayArea.append("Request is: \n");
readRequest(client);
sendResponse(client);
client.close();
|
private void | readRequest(java.net.Socket client)
BufferedReader request = null;
request = new BufferedReader(new InputStreamReader(client.getInputStream()));
String nextLine;
while (null != (nextLine = request.readLine())) {
// Ideally, we'd do something. But this is a very
// simple web server.
if (nextLine.equals("")) {
break;
} else {
_displayArea.append("\t" + nextLine + "\n");
}
}
_displayArea.append("---------------------------------------\n");
return;
|
private void | sendResponse(java.net.Socket client)
BufferedWriter response;
response = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
response.write(_mainPage);
response.flush();
|
public void | startListening()
ServerSocket serverSocket;
try {
serverSocket = getSSLServerSocket(443);
} catch (IOException e) {
return;
}
while (true) {
try {
Socket client = serverSocket.accept(); // wait here
processClientRequest(client);
//bad design-- should handle requests in separate threads
// and immediately resume listening for connections client.close();
} catch (IOException e) {
}
}
|