In this assignment, you will complete a client for a simple group chat service, which runs on Sandbox, port 45100 and 45101. There are two clients, the listener, which connects on port 45100, and the the sender, which connects on port 45101. The listener port simply accepts any connection, and just transmits lines to the client running there. The listener client simply connects and then prints each line which it receives. The sender side requires an account and password, which is authenticated using a simple challenge protocol described below. It then reads lines from the console and sends them to the server, which forwards them to all connected listeners. The project is to complete the sender.
Attached is all the code, except for the method body in the sender which you are to complete. You won't need to the server, since you can just contact the existing service on Sandbox. The server and sender both need the provided sha256 class. (There are plenty of existing libraries for this, but now you won't need to find one.)
There's really not much protocol. The listner simply connects, then loops to read and print each line. The sender uses a simple protocol to authenticate users.
client: | Connects over TCP |
server: | c5206256eb8f9b5a2069e3fef5c78a62\r\n |
client: | fred b72976880e9e9d1fc7e3370e89d2feadebc8c550a7a28df918fe0d8122c8bf11\r\n |
server: | +OK\r\n |
client: | This message is sent to all listeners.\r\n |
client: | So is this\r\n |
This authentication method allows the client to prove to the server that it knows the password without needing to transmit it over the connection.
Complete the go method in the sender. You should make the connection and attempt to authenticate. If the server refuses, print the message from the server and exit. If successful, loop reading lines from the console and sending them to the server. If the line typed is quit, do not send the server, but exit the loop and close the connected socket.
The numbers are sent in hex. The answer to the challenge is simply the hex representation of the sha256 hash of the challenge string, exactly as received, concatenated with the password. Using the included hashing class, this can look something like
Sender's main contains code to read the name of the host, port, user and password in any of several ways. These become the parameters to the method you have to write.