{"id":23080672,"url":"https://github.com/chen0040/spring-websocket-csharp-client-demo","last_synced_at":"2025-08-15T22:31:11.064Z","repository":{"id":85884814,"uuid":"113521575","full_name":"chen0040/spring-websocket-csharp-client-demo","owner":"chen0040","description":"Demo of connecting C# client to spring web application via websocket","archived":false,"fork":false,"pushed_at":"2017-12-08T04:35:00.000Z","size":965,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T16:19:56.188Z","etag":null,"topics":["c-sharp","duplex-communication","spring-boot","web-sockets"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chen0040.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2017-12-08T02:28:14.000Z","updated_at":"2023-07-19T02:23:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"691b57a5-acc2-4cf2-9cd1-064005edd64f","html_url":"https://github.com/chen0040/spring-websocket-csharp-client-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chen0040/spring-websocket-csharp-client-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fspring-websocket-csharp-client-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fspring-websocket-csharp-client-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fspring-websocket-csharp-client-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fspring-websocket-csharp-client-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chen0040","download_url":"https://codeload.github.com/chen0040/spring-websocket-csharp-client-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chen0040%2Fspring-websocket-csharp-client-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270637924,"owners_count":24620430,"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","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["c-sharp","duplex-communication","spring-boot","web-sockets"],"created_at":"2024-12-16T13:15:54.944Z","updated_at":"2025-08-15T22:31:11.053Z","avatar_url":"https://github.com/chen0040.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spring-websocket-csharp-client-demo\n\nDemo of connecting C# client to spring web application via websocket\n\n# Usage\n\n### WebSocket Spring Boot Server\n\ngit clone this project, run the \"./make.ps1\" powershell script in the project root directory to build spring-boot-application.jar\ninto the \"bin\" folder.\n\nRun the following command to start the spring-boot-application at http://localhost:8080\n\n```bash\njava -jar bin/spring-boot-application.jar\n```\n\nThe spring-boot-application defines an end point at http://localhost:8080/my-ws and sends a ping message to any connected client that subscribe to its topic \"/topics/event\" every 10 seconds. the angularjs demo can be viewed by navigating to http://localhost:8080 on your web browser.\n\n### C-Sharp WebSocket Client\n\nNow cd to csharp-client-proj (a modified version from https://github.com/huhuhong/websocket-csharp-net-stomp-client) and open the csharp-client-proj.sln in your Visual Studio IDE and run the Program.cs. The source code for the C# web socket client is shown below:\n\n```cs \nusing WebSocketSharp;\nusing (var ws = new WebSocket(\"ws://localhost:8080/my-ws/websocket\"))\n{\n\tint clientId = 999;\n\n\tws.OnOpen += (sender, e) =\u003e\n\t{\n\t\tConsole.WriteLine(\"Spring says: open\");\n\t\tStompMessageSerializer serializer = new StompMessageSerializer();\n\n\t\tvar connect = new StompMessage(\"CONNECT\");\n\t\tconnect[\"accept-version\"] = \"1.1\";\n\t\tconnect[\"heart-beat\"] = \"10000,10000\";\n\t\tws.Send(serializer.Serialize(connect));\n\n\t\t\n\t\t\n\t\tvar sub = new StompMessage(\"SUBSCRIBE\");\n\t\tsub[\"id\"] = \"sub-\" + clientId;\n\t\tsub[\"destination\"] = \"/topics/event\";\n\t\tws.Send(serializer.Serialize(sub));\n\t\t\n\t};\n\t\n\tws.OnError += (sender, e) =\u003e\n\tConsole.WriteLine(\"Error: \" + e.Message);\n\tws.OnMessage += (sender, e) =\u003e\n\tConsole.WriteLine(\"Spring says: \" + e.Data);\n\n\tws.Connect();\n   \n\tConsole.ReadKey(true);\n}\n```\n\nThe C# codes opens a connection to http://localhost:8080/my-ws and once the connection is openned sends to messages to spring-boot-application via the socket to subscribe to the \"/topics/event\" topic, which then allows the client code to receive message from the spring-boot-application.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fspring-websocket-csharp-client-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchen0040%2Fspring-websocket-csharp-client-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchen0040%2Fspring-websocket-csharp-client-demo/lists"}