Cryptography Reference
In-Depth Information
//Decipher the bytes read in
byte[]
plaintext=Ciphers.RSADecipherWSalt(buffer,decipherExp,modulus);
if (plaintext.length==1&&plaintext[0]==0) {
disconnectMsgSent=true;
closeAll();
} else {
//convert to a string and display
message = new String(plaintext);
displayArea.append(“\n”+message);
}
}
//Socket was closed from client side
} catch (SocketException se) {
//close connection and IO streams, change some components
closeAll();
}
closeAll();
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
Here is the closeAll() method. It puts a “Connection closing” string in the display area,
then shuts down its IO streams, then the socket. It turns off the message entry field, and
disables the disconnect button.
//Close socket and IO streams, change appearance/functionality of some components
private void closeAll() throws IOException {
displayArea.append(“\nConnection closing”);
output.close();
input.close();
connection.close();
//Disable message entry
enterField.setEnabled(false);
//We are not connected-turn off the disconnect button
disconnectButton.setEnabled(false);
}
Of course, here is the main() method of CipherChatServer, which simply sets up the
GUI, binds to a port for listening, then calls the go() method.
public static void main(String[] args) throws IOException {
CipherChatServer ccs=new CipherChatServer();
ccs.addWindowListener(
new WindowAdapter() {
Search WWH ::




Custom Search