{"id":21374873,"url":"https://github.com/banool/comp30023-assn2","last_synced_at":"2025-07-09T16:37:51.288Z","repository":{"id":90881348,"uuid":"58720045","full_name":"banool/comp30023-assn2","owner":"banool","description":"Assignment 2 for COMP30023 - Computer Systems, a game server and client written in C. Running live at mm.dport.me port 12340","archived":false,"fork":false,"pushed_at":"2020-05-20T14:56:03.000Z","size":222,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-07T02:50:25.255Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/banool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-13T08:51:33.000Z","updated_at":"2024-04-15T10:48:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"74620e22-6649-40c5-b92b-3d82a5f53a37","html_url":"https://github.com/banool/comp30023-assn2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/banool/comp30023-assn2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banool%2Fcomp30023-assn2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banool%2Fcomp30023-assn2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banool%2Fcomp30023-assn2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banool%2Fcomp30023-assn2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/banool","download_url":"https://codeload.github.com/banool/comp30023-assn2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banool%2Fcomp30023-assn2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264495614,"owners_count":23617588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T08:45:58.140Z","updated_at":"2025-07-09T16:37:51.205Z","avatar_url":"https://github.com/banool.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# COMP30023 - Assignment 2\nAssignment 2 for COMP30023 - Computer Systems.\n\n## Overview\nThis is assignment 2 for the unimelb subject COMP30023 - Computer Systems, a multithreaded TCP/IP server and client for the game Mastermind.\n\nThe basic implementation of the server involves creating and binding a socket and then waiting for clients to connect. Upon connection, a new socket is created and passed to a thread which is spawned to handle that game instance. The game logic itself is fairly straightforward and is handled in one main function with a couple of helpers.\n\nThe task also included running the server on both the university machines as well as the NeCTAR research cloud and testing various runtime characteristics relating to memory usage, disk usage, scheduling, etc.\n\nThere were some notable problems which had to be overcome:\n\n- Upon killing the server, we needed to write to log a collection of stats about the server's execution lifetime. These stats look into interesting characteristics using information from get_rusage() and /proc/, as well as basic information about the clients and their games.\n- In order to do this, the server had to be able to catch a SIGINT or SIGTERM and write to log first before servicing it. Using a signal handler did not initially work because the accept() function, which sits there waiting for a client to connect, would block it if the handler was activated. There were two ways to overcome this:\n    1. Put the accept() part of the code inside its own thread. Upon receiving the signal inside the parent thread, the child could just be stopped and then we would hopefully stop *its* child threads gracefully also.\n    2. Wrap the accept() in a poll() command. This function sits there and checks the specified socket(s) for activity in a non-blocking manner. When it does detect incoming traffic, then the execution is passed forward to accept(). This prevents any blocking from occurring.\n    \n    Solution number 2 was what I went with since it allowed me greater power of the control flow inside the server process without subthreading, and I also feel like it is standard practice when working with sockets.\n\n- When calling the pthread_create() function for a new process, you can only pass one argument through to it. As such, the program had to be designed with this in mind, making sure that the new thread had everything it needed to start. To solve this problem a struct called StateInfo was made which itself holds a list of structs (called Instance) for each of the currently running games. The Instance struct for each game would be initialised beforehand and then put into StateInfo. Once the thread was made, the appropriate Instance would be relocated using the thread id, which ended up working quite well.\n\nThe client itself was fairly straightforward to write. After receiving a welcome message, it comprises of a simple loop which waits for user input, sends it to the server, waits for the response and then repeats until it gets a message indicating that it has won, lost or run out of turns, at which point the game is over and execution ends.\n\n\n## Directory structure\n\nThe root directory contains all the code and header files, including makefile, this readme, the spec. It also contains the final report.\n\n- **testing** contains files used for testing the server under heavy load. This includes a text file with a single sample input set, as well as a python script which spawns a user defined number of clients simultaneously and bombards the server with game traffic. Note that the tester contained within should not be run on the same machine as the server or you will get weird results.\n\n## Results\n\nOnce I get my results back for this assignment, I will post the result so as to provide an indication of its quality.\n\n### Update\n\nFinal Result: 14.5/15\n\nClient - Server: 3/3\nConcurrency: 3/3\nLog file: 2.5/3\nNectar cloud: 2/2\nCode Quality: 2/2\nReport: 2/2\n\nThe 0.5 lost was because I didn't flush to buffer after writing to each line of the log. I have since done so by adding the line `fflush(log_f);` in logging.c, which fixed the problem.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanool%2Fcomp30023-assn2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanool%2Fcomp30023-assn2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanool%2Fcomp30023-assn2/lists"}