In today's studio you will explore additional asynchronous programming features in Rust, including different ways to return results and to wait for completion of asynchronous tasks.
Please complete the following required exercises. I encourage you to please work in groups of 2 or 3 people on each studio (and the groups are allowed to change from studio to studio) though if you would prefer to complete any studio by yourself that is also allowed.
As you work through these exercises, please record your answers, and when you finish them please log into Canvas, select this course in this semester, and then on the Canvas page for this studio assignment upload (1) a file containing your answers and (2) any code you produced while answering the exercises. Only one submission per team, please, and if you need to re-submit it the person who originally submitted the studio should please be the one to do that.
Make sure that the name of each person who worked on these exercises is listed in the first answer, and make sure you number each of your responses so it is easy to match your responses with each exercise.
As the answer to the first exercise, list the names of the people who worked together on this studio.
Log in using ssh into shell.cec.wustl.edu using your WUSTL
Key id and password, issue the qlogin command to
get onto one of the Linux Lab machines, and then within the directory you
created for this course, add a new directory for this studio.
In that new directory, use the cargo new command to create new client and
server packages (named e.g., rustasyncclient2 and
rustasyncserver2).
Change into the src directory within each of those packages, remove the
main.rs file that was automatically generated there, and copy over the
appropriate client or server code from your previous studio.
Try to compile and run your programs as you did in the last exercise of the previous studio, and as the answer to this exercise please show the errors that were produced.
Update the dependencies in your client and server packages' Cargo.toml
files so that they can compile and run as they did in the last exercise of the
previous studio, and as the answer to this exercise please show the output that
was produced.
For this exercise and the following ones, please remember that sockets
tend to buffer data, and so that in order for the data to go through you may need
to either (1) flush the socket explicitly and (2) call the
socket's shutdown method (using Shutdown::Write when the
client finishes writing to it, and using Shutdown::Both when the
server finishes writing to it); or, you could just use buffered readers and
writers that will mostly do that for you.
Modify your client so that it concatenates all of its command line arguments
except for the program name into a string, or if there are no command
line arguments other than the program name it should instead initialize the
string with "quit". If the socket is established
correctly, the client should send the string across it to the server.
Modify your server so that after it successfully establishes a socket it reads from the socket and prints out what it read. Compile and run your server and then run your client with different command lines. As the answer to this exercise please show your client and server code and the output that each of them produced.
Modify your server so that if the string it read from the socket was
"quit" then after it prints that out the server program ends.
Compile and run your server program, and run your client program with a different
command line and then with "quit" as its only command line argument.
As the answer to this exercise, please show the output that was produced by both
programs.
Modify your server so that if the string it read from the socket was
not "quit", then instead of printing out the string it
sends the string it read back across the
socket to the client.
Modify your client so that if (and only if) the string it sent to the server was
not "quit", then after it sends the string to the server it reads from
the socket and prints out what it received. Compile and run your server program, and
compile and run your client program with a different command line and then with
"quit" as its only command line argument. As the answer to this
exercise, please show the output that was produced by both programs.
Modify your server so that if the string it read from the socket was
not "quit", instead of using the main program thread to send the
string it read back across the socket to the client, it spawns a new
asynch task that does that and moves the socket into that task.
Compile and run your server program, and run your client program with the same command lines you ran it with in the previous exercise. Confirm that the same output as in the previous exercise was produced, and as the answer to this exercise, please show your updated server code.
For this studio, please turn in the following:
Page updated Friday July 17, 2026, by Chris Gill.