Skip to content

W12 ‐ Concurrent and TCP Socket Programming (ASSESSED)

Atanbori edited this page Jan 15, 2025 · 1 revision

CMP9133 - Workshop 12

University of Lincoln School of Engineering and Physical Sciences CMP9133 – Programming Principles

Task 1 (assessed): TCP Socket - Compute Statistics on Number List

  1. Write a C++ program for the client that allows the user to input a list of numbers.
  2. Implement functionality to send the list of numbers to the server over a TCP socket connection.
  3. Write a C++ program for the server that listens for incoming connections on a specified port.
  4. Implement functionality to receive the list of numbers from the client.
  5. In the server program, parse the received list of numbers and compute the average, minimum, maximum, and median values.
  6. Send the computed statistics (average, minimum, maximum, and median) back to the client.
  7. Implement error handling mechanisms for cases such as network communication errors, invalid input, or incorrect message formatting.
  8. The client program should receive the computed statistics from the server and display them to the user.
  9. Consider using appropriate data structures and algorithmic approaches to calculate the statistics efficiently.

Task 1 focuses on setting up a client-server system using TCP sockets, sending data from the client to the server, and performing statistical calculations on the received data in the server. It involves parsing, calculations, and proper handling of different scenarios. Students should also consider data validation and error handling to ensure the program is robust.

Task 2 (assessed): Implement a program to process a large dataset concurrently using multiple threads and a shared resource, and then merge the results.

Instructions:

  1. Create a C++ program that reads a large dataset from a file.
  2. Implement a class, let's say DataProcessor, that processes the dataset (e.g., performs some computations or transformations on the data) in parallel using multiple threads.
  3. Divide the dataset into equal-sized chunks and distribute them among threads for processing.
  4. Use locks or other synchronization mechanisms to manage shared resources, such as the output or intermediate result storage.
  5. Each thread should process its assigned chunk independently and store the results in a shared data structure.
  6. Once all threads have completed their processing, merge the results from each thread into the final result.

By completing task 2, students will gain experience in:

  • Reading input and managing large datasets in a multithreaded environment.
  • Synchronizing access to shared resources using locks or synchronization primitives.
  • Efficiently partitioning the dataset for parallel processing.
  • Merging results from multiple threads into a final output.
  • Handling I/O operations and managing file output.