CIT5950 – Project 3 Part b Solved

50.00 $

Category: Tags: , ,

Description

5/5 - (1 vote)

1             Project 3b: Multi-threaded Server

Overview

In this part, you will enhance your TCP server in Part A (tcpserver), such that the new server

(multi-tcpserver) can handle multiple concurrent client requests using multi-threading. In the server, when a client connection is accepted (via the accept API), the server should create a separate thread to handle the Handshake Protocol using the socket descriptor returned by the accept call. We have provided a sample C program for multi-threading (sample_thread.c) in the course module in which you learned threads.

Conceptually, Part B is just a refactoring effort from Part A. You would be putting all the client communication code into a thread function, which should be passed into pthread_create.

1.1            Requirements

1.1.1           Source files and arguments

All of the requirements from Part A remain the same, with the following changes:

  • You MUST implement the server in multi-tcpserver.c instead of tcpserver.c • The makefile MUST create the executable multi-tcpserver instead of tcpserver
  • You MUST link the pthread library (you will get a compile error if you forget!).

1.1.2           Handshake Protocol

All of the requirements from Part A apply to Part B.

1.1.3           End of Line characters

All of the requirements from Part A apply to Part B.

1.1.4           Multi-threading

  • You MUST use multi-threading for this part. The autograder will do a static analysis to ensure you call the appropriate functions. See the The Autograder section below for details on this analysis.
  • Your multi-thread MUST handle interleaving correctly. This means that clients may send messages out of order, e.g. Client A may send HELLO X followed by Client B sending HELLO Y. See the Testing Interleaving section below for how to do this locally.
  • Threads should run as detached threads. Calling pthread_join can lead to non-concurrent operations and MUST NOT be used.

1.1.5           Miscellaneous

  • You SHOULD reuse the client from Part A. You do not need to make any changes to the client for this part (unless there are still bugs).
  • You MAY assume that no more than 100 concurrent client connections will attempt to connect to the server.
  • All of the requirements from Part A apply to Part B.

1.2            Suggested Approach

This is a suggested approach. You are free to implement the solution in any manner you want.

  1. Start by copying your Part A server code into the new source file.
  2. If you haven’t already done so, refactor your code such that all of the handshake functionality is in a new helper function. What should be left is a small loop that accepts connections and then calls the helper function for the handshakes. Your server should still work as a sequential server at this point.
  3. You’ll want to create an array of thread IDs, this will allow you to keep track of threads as they are created and destroyed. You only need to do this once.
  4. Replace the call to the helper function with a call to pthread_create, with the helper function as an argument. Be sure to read the manual pages to ensure you setup the call correctly. Store the thread ID into the thread ID array.
  5. Test your multi-threaded server by running a client. You should see all the handshakes print as expected.
  6. Further test your multi-threaded server by running several clients back to back, sequentially. You should see each set of clients print the appropriate messages, in order.
  7. Stress test your multi-threaded server by running several clients concurrently. The messages may print out of order due to interleaving. See the Testing Interleaving section below.

1.3            Submission

  • Your solution MUST compile when running make clean followed by make. Please do check this before submitting. Submissions that fail to compile will receive a 0.
  • You MUST submit all source and header files, and the makefile, in a tarball (.tar.gz) to the Gradescope assignment CIT 5950 Project 3b.
  • Your tarball SHOULD NOT contain compiled binaries or demo code files. • You have unlimited submissions until the due date specified by the syllabus.

1.4            Grading

Project 3b will be marked on five rubric items. The descriptions for these tests are in the The Autograder section.

There is no peer review for this assignment. You will not be marked on code style.

The score at the due date is final. Do note that they do not sync with Canvas immediately; the course staff must manually release them.

  1. Static Analysis : 0 points
  2. Proxy Test : 20 points
  3. Load Test : 30 points
  4. Interleaving Clients Test : 30 points
  5. Server Error Checking Test : 20 points

Total : 100 points

  • 3b-hdm9xe.zip