Cryptography Reference
In-Depth Information
The constructor does the typical thing for a GUI; it lays out all the components on the
frame, and displays it. However, this constructor also produces the public and private keys
of the client when it calls the makeKeys() method, which we will see later.
public CipherChatClient() {
super(“Cipher Chat Client”);
//Establish keys for RSA cipher
makeKeys();
//Lay out the components and display the frame
setLayout(new GridLayout(2,1));
top.setLayout(new GridLayout(3,1));
add(top);
bottom.setLayout(new GridLayout(1,1));
add(bottom);
connectButton.addActionListener(this);
enterField.setEnabled(false);
enterField.addActionListener(this);
top.add(serverField);
top.add(connectButton);
top.add(enterField);
bottom.add(displayArea);
setSize(400,300);
show();
}
The client does a lot of work in its actionPerformed() method. The ActionEvents gener-
ated here may mean more than one thing. The events are:
1.
The user hit enter in the message entry field, and wants to send the message. We send this
message down the output stream the way we did for the server.
2.
The user pressed the connect/disconnect button. This can mean one of two things:
a)
We are currently connected, and the client wishes to disconnect. To disconnect, we
must first send the terminate message 0 (enciphered) to the server. Then we call the
closeAll() method, which closes the streams and sockets, and changes the appear-
ance/functionality of components on the GUI.
b)
We are currently disconnected, and the client wishes to connect. To connect (or recon-
nect) the client must attempt to establish a socket with the specified server, open its
IO streams, exchange public keys with the server, and enable the message entry field.
It then calls the go() method, which listens for input in a separate thread.
All of these cases are handled here.
public void actionPerformed(ActionEvent e) {
Object source=e.getSource();
//Client pressed enter in the message entry field-send it
if (source==enterField) {
Search WWH ::




Custom Search