{"id":16161532,"url":"https://github.com/gamemann/csharp-websockets-chat","last_synced_at":"2025-10-03T16:45:50.496Z","repository":{"id":234030058,"uuid":"787174286","full_name":"gamemann/csharp-websockets-chat","owner":"gamemann","description":"A small project that allows a client and server to communicate together similar to a chat room. I made this project to learn more about web sockets in CSharp/.NET and manage multiple web sockets at once. ","archived":false,"fork":false,"pushed_at":"2024-04-18T04:12:30.000Z","size":1865,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T12:30:02.401Z","etag":null,"topics":["c-sharp","chat","cli","csharp","dotnet","net","room","simple","socket","ssl","web","web-socket","web-sockets","websocket","websockets"],"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/gamemann.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":"2024-04-16T02:58:55.000Z","updated_at":"2025-02-16T12:55:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d4b7c7b-c06e-4e97-bef6-94b86ad1059e","html_url":"https://github.com/gamemann/csharp-websockets-chat","commit_stats":null,"previous_names":["gamemann/csharp-websockets-chat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2Fcsharp-websockets-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2Fcsharp-websockets-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2Fcsharp-websockets-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamemann%2Fcsharp-websockets-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gamemann","download_url":"https://codeload.github.com/gamemann/csharp-websockets-chat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243950813,"owners_count":20373664,"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":["c-sharp","chat","cli","csharp","dotnet","net","room","simple","socket","ssl","web","web-socket","web-sockets","websocket","websockets"],"created_at":"2024-10-10T02:25:35.595Z","updated_at":"2025-10-03T16:45:50.371Z","avatar_url":"https://github.com/gamemann.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a small project that utilizes CSharp and the [.NET library](https://dotnet.microsoft.com/en-us/learn/dotnet/what-is-dotnet) (7.0). This program allows you to establish multiple web sockets at once (client -\u003e server and server -\u003e client both supported). This is intended to run on Linux-based operating systems that support .NET 7.0 (e.g. using the `dotnet` package). It is possible this works with Windows, but I haven't tried testing it. This project should also work with .NET 8.0, but I haven't tested that as well.\n\nThis program operates as a very simple one-on-one chat room. When connected, the client and server can exchange basic UTF-8 text messages with each other.\n\nI made this project to learn more about web sockets in CSharp/.NET along with how to manage multiple web sockets receiving/sending data concurrently via asynchronous methods.\n\n## Demo\nHere's a GIF video demonstrating the functionality of the program. We don't use SSL in our demonstration and establish the client and server both locally using `127.0.0.1` (localhost).\n\n![Demo GIF](./images/csharp-websockets-chat-demo.gif)\n\n## Building \u0026 Installing\n### Prerequisites\n#### .NET 7.0\nThe .NET 7.0 library is required to run this project. You can install this library manually or through a package manager if your Linux distro supports it.\n\nOn Ubuntu/Debian-based systems, you may install Dotnet using the below command(s).\n\n```bash\n# Typically this is only required for Debian.\nwget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb\nsudo dpkg -i packages-microsoft-prod.deb\nrm packages-microsoft-prod.deb\nsudo apt update\n\n# Install .NET 7.0.\nsudo apt install -y dotnet-sdk-7.0\n```\n\n#### Building \u0026 Running\nIf you want to build and run the project. You can use the following command.\n\n```bash\ndotnet run\n```\n\nIf you want to only build the project, you can use the following command.\n\n```bash\ndotnet build\n```\n\nMake sure you're in the same directory as the `csharp-websockets.csproj` file when performing the above commands.\n\n## Command Line\nThe following command line arguments are supported.\n\n* **-z --cfg** =\u003e The path to the config file. By default, it looks for `./conf.json`.\n* **--nolisten** =\u003e Prevents the listen server from activating.\n* **--host** =\u003e Overrides the host address to listen on.\n* **--port** =\u003e Overrides the port to listen on.\n* **--ssl** =\u003e Overrides the listen SSL option.\n* **-l --list** =\u003e Lists all values of config and exits. \n\n## Configuration\nA config file on the file system is read and parsed via the JSON syntax. The default path it checks for is `./conf.json`. However, it can be changed via the config path command line option listed above.\n\nHere are the config options. Please keep in mind you will need to remove the comments (`//`) if copying below. I recommend taking a look at the [conf.ex.json](./conf.ex.json) file if you want to copy the configuration without any errors.\n\n```\n{\n    // Whether to activate the listen server.\n    \"listen\": true,\n\n    // The host to listen on.\n    \"listenHost\": \"127.0.0.1\",\n\n    // The port to listen on.\n    \"listenPort\": 2222,\n\n    // Whether to listen with SSL.\n    \"listenSsl\": false,\n\n    // An array of startup client connections.\n    \"startupConnections\": [\n        {\n            // The startup connection host.\n            \"host\": \"127.0.0.1\",\n            \n            // The startup connection port.\n            \"port\": 2223,\n\n            // Whether to use SSL with the startup connection.\n            \"ssl\": false\n        }\n    ]\n}\n```\n\n## Usage\nWhen starting up the program, you will be prompted with the following commands you can use.\n\n* **ls** - List all server connections. The number at the beginning represents the index which should be used with other commands.\n* **lc** - List all client connections. The number at the beginning represents the index which should be used with other commands.\n* **new `\u003cip\u003e` `\u003cport\u003e` `\u003cssl\u003e`** - Establish a new client connection to `\u003cip\u003e`:`\u003cport\u003e`. `\u003cssl\u003e` is optional and to disable SSL, use **no**.\n* **cc `\u003cidx\u003e`** - Send/receive messages for client connection at index `\u003cidx\u003e`.\n* **cs `\u003cidx\u003e`** - Send/receive messages for listen server at index `\u003cidx\u003e`.\n* **rc `\u003cidx\u003e`** - Remove client at index `\u003cidx\u003e`.\n* **rs `\u003cidx\u003e`** - Remove server at index `\u003cidx\u003e`.\n* **h** - Print top/help menu.\n* **q** - Exit program.\n\nWhen connected to a chat session via the `cc` and `cs` commands, you can send the message `\\q` to detach the current chat session and return to the main menu.\n\n## Notes\n* This project is still a work in progress. I have not yet tested SSL.\n* Only one connection to the listen server is supported at the moment. New connections will override the previous connection. However, I may add support for multiple connections in the future when I have more time.\n* There are some code that can definitely be improved on/organized better.\n\n## Credits\n* [Christian Deacon](https://github.com/gamemann)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fcsharp-websockets-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgamemann%2Fcsharp-websockets-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamemann%2Fcsharp-websockets-chat/lists"}