CSc 423 Assignment 2

Message For You, Sir

Assigned
Due

Feb 11
95 pts
Feb 28

2/13: Modified the getpass.h header so it should work on either platform. But you still don't need to include it on Linux.

Write a client program which can interact with the Message Repository Protocol server on sandbox.mc.edu. (This is a private protocol, so you are not likely to find it running elsewhere.)

Your program should have the following features.

  1. Accept the name of the host to connect to on the command line. You may take a port number, but your program should connect on the standard port, 45301, if none is specified.
  2. After starting, the program should request and read an account and password. You shouldn't display the password as it is typed, perhaps by using getpass (see below), though this is not required for this exercise. If the server will not accept these credentials, say so and ask again. Keep asking until the user gets it right (or uses ^C to kill the program).
  3. After a user/password pair is accepted, enter a loop, whose body repeatedly does this:
    1. Print the number of messages in queue for the logged-in user.
    2. Prompt for, and read a one-character command from the console.
    3. If the command was q, close the server connection and exit.
    4. If the command was r, get a message from the server and print it on the console. If there no message available, you program should say so.
    5. If the command was s, the s should have been followed by a username. Send a message to that user. If the user does not exist, say so. Otherwise, read the message from the console, prompting for each line. The message ends when the user enters two consecutive blank lines. Send these lines to the server as a message body. If the user enters a line which contains exactly a period (the terminator in the network protocol), silently add a space to it so you will not terminate your transmission to the server. Of course, when the user does terminate the message input, you should send the dot line to the server to close the message body. After sending the message, print a message indicating its success or failure, as reported by the server.
If the server does something it shouldn't, or if it issues a 120 error, your program should print a reasonable message and halt.

Use the cleansocks library to write yor program.

Here's what mine looks like:

[bennet@bennet msgcli]$ msgreader sandbox.mc.edu Msg login: fred Msg password: *** Invalid login. *** Msg login: fred Msg password: === 0 messages === --- r | q | s <to> : s alice *** No such user alice *** === 0 messages === --- r | q | s <to> : s sally --- Enter the message. End with two empty blank lines: > I'm looking for more pencils so I can keep > my pockets full and prove I'm a good nerd. > Can you lend me a few? > > --- Mesage sent OK. --- === 0 messages === --- r | q | s <to> : q [bennet@bennet msgcli]$

Or another:

[bennet@bennet msgcli]$ msgreader perlie.mc.edu Msg login: sally Msg password: === 1 messages === --- r | q | s <to> : r === Message: === ----------------------------------------------------------- === From fred at 23:19:26 Feb 01, 2020 === I'm looking for more pencils so I can keep my pockets full and prove I'm a good nerd. Can you lend me a few? ----------------------------------------------------------- === 0 messages === --- r | q | s <to> : s fred --- Enter the message. End with two empty blank lines: > No, I'm using them to keep my monitor balanced. > > --- Mesage sent OK. --- === 0 messages === --- r | q | s <to> : q [bennet@bennet msgcli]$

The message server has accounts for each of you, and a few others which can be shared, to use for testing. We'll discuss those in class.

The message server has accounts for each of you with the same name as your Sandbox login. The passwords are the same login names. If you like, you can change your password with this message server password tool, which also serves as an example of code which talks to the server.

Getpass

For reading the password without echo, you might want to use the getpass function. In Linux, you can just use it. (It is marked obsolete in the documentation, but I'll stop using it when they add a replacement.) The getpass, function will read the password in the command window without it being displayed on the screen.

Getpass is standard on Linux. There a Windows version here: header and implementation. Don't add this code to your source file, but download them and add the files to our CodeBlocks project. Then add #include "getpass.h" to your program. CleanSocks will build them correctly.

Alternatively, if you have the method readpassphrase installed, you can use that. It is considered a superior replacement for getpass, but may not be as widely available.

Submission

When your program is working, nicely commented and properly indented, submit it using the form here. Note that the submit form has space for a header file and extra code file. These are optional; you may use them if you wish to divide your program into parts.