{"id":22021973,"url":"https://github.com/knightchaser/gotcp","last_synced_at":"2025-05-07T06:42:43.720Z","repository":{"id":216743674,"uuid":"742198684","full_name":"KnightChaser/goTCP","owner":"KnightChaser","description":"A simple CLI based multiuser chatting app with GO TCP socket, based on the client-server model","archived":false,"fork":false,"pushed_at":"2024-01-15T14:22:55.000Z","size":9308,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T07:22:19.300Z","etag":null,"topics":["chatting-app","cli","cli-app","docker","golang","small-project","socket","socket-programming","tcp"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/net","language":"Go","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/KnightChaser.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}},"created_at":"2024-01-12T00:34:05.000Z","updated_at":"2024-05-27T06:01:34.000Z","dependencies_parsed_at":"2024-01-15T16:25:19.706Z","dependency_job_id":null,"html_url":"https://github.com/KnightChaser/goTCP","commit_stats":null,"previous_names":["knightchaser/gotcp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnightChaser%2FgoTCP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnightChaser%2FgoTCP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnightChaser%2FgoTCP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KnightChaser%2FgoTCP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KnightChaser","download_url":"https://codeload.github.com/KnightChaser/goTCP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831098,"owners_count":21810777,"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":["chatting-app","cli","cli-app","docker","golang","small-project","socket","socket-programming","tcp"],"created_at":"2024-11-30T06:16:54.845Z","updated_at":"2025-05-07T06:42:43.714Z","avatar_url":"https://github.com/KnightChaser.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goTCP\n![Go](https://img.shields.io/badge/go-%2300ADD8.svg?style=for-the-badge\u0026logo=go\u0026logoColor=white)\n![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge\u0026logo=docker\u0026logoColor=white)\n![PowerShell](https://img.shields.io/badge/PowerShell-%235391FE.svg?style=for-the-badge\u0026logo=powershell\u0026logoColor=white)\n![Shell Script](https://img.shields.io/badge/shell_script-%23121011.svg?style=for-the-badge\u0026logo=gnu-bash\u0026logoColor=white)\n\nA simple **real time** multiuser chatting application with TCP socket, based on the client-server model, built with Go. Every instance is dockerized and automated by scripts for rapid setup.\n\n\u003e Demonstration(picture)\n![img](./READMEasset/figure1.png)\n\nThis simple project is a simple real-time chat application(because it's simple, please consider the naive interfaces.) implemented in the Go programming language. It consists of a server (`tcpserver/tcpserver.go`) and a client (`tcpclient/tcpclient.go`) that communicate over a TCP network. The application allows users to connect to the server, set a username, and exchange messages in real time.\n\n### Feature\n* **Server-Client Architecture**: The application follows a server-client architecture, enabling multiple users to connect to the server simultaneously.\n\n* **Real-Time Messaging**: Users can exchange messages in real time. When a user sends a message, it is immediately broadcast to all other connected users.\n\n* **Username Registration**: Users are prompted to set a username when connecting to the server. This username is used to identify users in the chat.\n\n* **Graceful Termination**: Users can terminate their connection gracefully by typing `!exit` in the client interface, triggering a clean disconnection from the server. In server, you can just stop server process via hitting `[ctrl]+[c]` keybinding. It will gracefully terminate the whole session.\n\n* **Dockerized**: Server and client are encapsulated by docker. Because there are few lines of docker-related commands for every instance, this project provides a \"one-stop script\" that processes setting up, docker building, and docker execution at once\n    * [x] Windows(Powershell script(`dockerbuild.ps1`))\n    * [x] Linux(Shell script(`dockerbuild.sh`))\n\n\n### Execution\nBecause this project's theme is communicating with each other, the docker networking setup is very important. You just need to execute the \"one-stop script\" that this project provides. **Support both Windows and Linux!**\n* **Server**: `tcpserver\\dockerbuild.ps1` if **Windows**, `sudo bash tcpserver/dockerbuild.sh` if **Linux** (Only one instance is required, so execute this script only once at the same time.)\n* **Client**: `tcpclient\\dockerbuild.ps1` if **Windows**, `sudo bash tcpclient/dockerbuild.sh` if **Linux** (You may create client instances as many as you want.)\n\n### Docker setup explanation (networking)\n* **Server** (Windows Powershell)\n```powershell\ndocker network remove goTCPnet\ndocker network create goTCPnet --subnet=192.168.111.0/24\ndocker build . --tag gotcpserver:0.1\ndocker run --rm --name gotcpserver --network goTCPnet --ip 192.168.111.111 -p 7777:7777 gotcpserver:0.1\n```\nBecause the server accepts clients' requests remotely, IP address and port settings should be synchronized. By default, server setup creates a docker network `goTCPnet` and designates the network range as `192.168.111.0/24`, server process address as `192.168.111.111(/24)` manually. This setting should be synchronized with `tcpserver\\tcpserver.go`'s `listeningAddressPort` variable that the server process refers to for setting up the address to accept clients' requests.\n```go\nlisteningAddressPort := \"192.168.111.111:7777\"\n```\n\n* **Client** (Windows Powershell)\n```powershell\n# Get the USERNAME from user input\n$USERNAME = Read-Host \"Enter USERNAME \"\nWrite-Output \"You're now @$USERNAME\"\n\n# Generate a 6-digit random hex string (to make every container have different container names)\n$RandomHex = -join ((1..6) | ForEach-Object { Get-Random -Minimum 0 -Maximum 16 } | ForEach-Object { $_.ToString(\"X\") })\n$containerName = \"gotcpclient${USERNAME}${RandomHex}\"\n\n# Build and run Docker container\ndocker build -t gotcpclient:0.1 --build-arg --no-cache .\ndocker run --rm --network goTCPnet --interactive --tty --name $containerName gotcpclient:0.1 ./tcpclient -username $USERNAME\n```\nBecause the client (`tcpclient\\tcpclient.go`) accepts username as an argument `-username`, It asks a user for the username for every single created instance and applies them to the execution arguments. Suppose users may use multiple same names(`-username` argument). In that case, there might be some unexpected docker container name collisions, so client setup appends a 6-digit random hexadecimal string like `gotcpclient${USERNAME}${RandomHex}` to ensure every client container name should be globally unique. Client processes should be interactive to receive and print messages from users and server instances, `--interactive` and `--tty` options should be provided too.\n\n### Note and contribution\n* Because this was made for learning how to make \"something\" with Go, Docker, Socket communication, and Github, the implementation is naive and not-so-professional, I kindly ask for your consideration.\n* Any contribution to this project is greatly appreciated.\n\n\u003cbr\u003e\n\n**@KnightChaser**, a pro spaghetti chef in Gachon University, Cybersecurity department.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknightchaser%2Fgotcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknightchaser%2Fgotcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknightchaser%2Fgotcp/lists"}