Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part 1. TCP Sockets (10 points)

The first application you will write is a simple web client and server, using a TCP (Transmission Control Protocol) socket.

Your task

To get started, cd into the assignment repository you cloned. Then, cd into the tcp directory.

Create a new cargo project called server with cargo new server. cd into the server directory. This is where you will implement your web server.

You will follow the instructions in the Listening to the TCP Connection section of Chapter 21 in the Rust textbook, with the following adjustments:

  • Ignore the instructions for creating a new cargo project called hello. You’ll write your code in the src/main.rs file in the server project you just created.

  • Skip the instructions for testing your server with a web browser. This will not work if you’re connected to mcnulty. Instead, you’ll be provided with a simple web client (based on the code presented in class) that you can use to test your server.

Testing Your Server

To test your server, you will need to open up another terminal window to run the client code. You can open up a second terminal in VSCode, or you can open a separate one (just make sure you’re ssh’ed into mcnulty).

You will first start your server by running cargo run from the tcp/server directory.

Then, you will run your client with cargo run in the tcp/client directory.

At this point, the cient code will panic and have a Connection reset by peer error message. This is ok! It happens because the sever doesn’t do anything with the client (yet); it accepts the connection and immediately closes it.

The server code should print out Connection established!.

When you’re done running the server, you can kill the process with Ctrl-C.

You will next follow the instructions in the Reading the Request section of Chapter 21 of the Rust textbook. Once again, ignore any instructions to use the web browser, as this won’t work with mcnulty. You should only follow the instructions for editing src/main.rs in your server project.

You can test your server in the same way as decribed above. At this point, you’ll see more info about the actual request made by the client.

Read the A Closer Look at an HTTP Request section. You do not need to make any code changes with this section.

Finally, follow the Writing a Response section.

Make sure to test your server again. Your client will print out the time elapsed. Make a note of this number; it will be relevant for Part 3.

At this point, your client and server are talking to each other! Move on to Part 2, to work on a different implementation of a web server.