{"id":20945320,"url":"https://github.com/bofeiw/comp3331-tcp-message-client-server","last_synced_at":"2026-04-26T19:32:41.141Z","repository":{"id":124399790,"uuid":"222106120","full_name":"bofeiw/comp3331-tcp-message-client-server","owner":"bofeiw","description":"My solution to the computer network (COMP3331) assignment at UNSW, 2019 term 3.","archived":false,"fork":false,"pushed_at":"2019-11-28T14:33:35.000Z","size":465,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-26T08:35:06.040Z","etag":null,"topics":["comp3331","meessage","p2p","p2p-chat","tcp","tcp-client","tcp-server","tcp-socket","unsw"],"latest_commit_sha":null,"homepage":"","language":"Python","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/bofeiw.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":"2019-11-16T13:50:34.000Z","updated_at":"2022-06-16T14:45:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"5b27ac9c-ec4d-4c00-a121-183c5c007138","html_url":"https://github.com/bofeiw/comp3331-tcp-message-client-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bofeiw/comp3331-tcp-message-client-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bofeiw%2Fcomp3331-tcp-message-client-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bofeiw%2Fcomp3331-tcp-message-client-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bofeiw%2Fcomp3331-tcp-message-client-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bofeiw%2Fcomp3331-tcp-message-client-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bofeiw","download_url":"https://codeload.github.com/bofeiw/comp3331-tcp-message-client-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bofeiw%2Fcomp3331-tcp-message-client-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32310804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T19:15:34.056Z","status":"ssl_error","status_checked_at":"2026-04-26T19:15:15.467Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["comp3331","meessage","p2p","p2p-chat","tcp","tcp-client","tcp-server","tcp-socket","unsw"],"created_at":"2024-11-18T23:47:39.885Z","updated_at":"2026-04-26T19:32:41.123Z","avatar_url":"https://github.com/bofeiw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Comp3331 Assignment Report - Bofei Wang\n\nThis is my solution to the computer network (COMP3331) assignment at UNSW, 2019 term 3.\n\n**If there are any similar assignments in the future, do not copy directly but use as a reference only wisely.**\n\n## Program Design\n\nStructure:  \n- client *folder where client resides*\n    - client.py *client entry file*\n- server *folder where server resides*\n    - credentials.txt *credentials to feed to server*\n    - server.py *server entry file*\n    - UserManager.py *auxiliary file to help server delegating tasks*\n\n## Application Layer Message Format\n\nMessages are communicated as json format.\n\nGenerally, an `action` is a must in a message to indicate the intention of a message. Depends on intentions of a message, other fields in the json are different.\n\nFor example in when `action` is set to `login`, server's reply message will include a `status` field to tell the client if it is authenticated or not. \n\nAnother example, when server handles a `action: broadcast` requested by a user, it sends a `action: receive_message` json to some other users, whereas when it handles a `action: receive_broadcast`, it sends a `action: receive_message` to the user who should receive the message.\n\n## How Your System Works\n\nQuick command reference:\n\nTerminal 1: server\n```shell script\ncd server\npython3.7 server.py 12346 10 60 \n```\n\nTerminal 2: client\n```shell script\ncd client\npython3.7 client.py localhost 12346\n```\n\nOn server starts, it starts to listen to every new connections and create a thread for it, and the new thread will listen to every incoming data requested by client. Generally all the messages will be checked by UserManager and reply message will be send back to client immediately. Only when a user is not online, the messages are temporarily pushed to a pending list and another thread will continuously check the pending list and process these message when the user is online.\n\nOn client starts, it establish a TCP connection to the server and creates two threads - one for displaying server incoming messages and another for handling user inputs and send the messages to the server.\n\nP2P is implemented by client retrieving address and port number of another client and establish a TCP connection directly with another user.\n\n## Design trade offs\n\nOne of the trade off is to use multi-processing or multi-threading. Multi-threading is chosen because it is easier to manager the communications between threads.\n\nAnother trade off is the format of the messages. json is chosen because it is light weight and is best fit for a small scaled assignment.\n\nOne more trade off is the number of manager classes to create. Only a UserManager is finally implemented and it turns out that it is sufficient. Initially I was thinking to create classes like CredentialManager, MessageManager, TimeoutManager etc., but because of the functionality of the messaging application are quite limited, one UserManager is sufficient for all the functions.\n\n## Possible Improvements\n\nEfficiencies of the messaging application can be improved. Currently server checks input in every client thread in a while loop without pausing at all and updates users every 0.1 seconds. It is very recourse-wasteful. A better implementation is to use event driven programming where it only updates or runs when there is a new events, instead of looping infinitely.\n\n## Extensions And How You Could Realise Them\n\nP2P messaging is implemented.\n\n## Does Not Work Under Any Particular Circumstances\n\nYay - it works under most of common circumstances on CSE machine!\n\nIf you are unable to run the server in a particular port, try a different one - that port may be busy.\n\n## Segments Of Code That You Have Borrowed\n\n- `server.py` and `client.py` is developed based on the multi-threading codes provided by COMP3331.\n- https://stackoverflow.com/a/4653306/12208789 at client.py to prevent having the prompt overwritten by other threads in Python\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbofeiw%2Fcomp3331-tcp-message-client-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbofeiw%2Fcomp3331-tcp-message-client-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbofeiw%2Fcomp3331-tcp-message-client-server/lists"}