{"id":25979229,"url":"https://github.com/bjorg/blazorwebsocket","last_synced_at":"2026-03-08T01:34:46.803Z","repository":{"id":66875545,"uuid":"263964345","full_name":"bjorg/BlazorWebSocket","owner":"bjorg","description":"This repository contains a simple application that that connects to the `wss://echo.websocket.org` to show how WebSocket connectivity works in Blazor WebAssembly.","archived":false,"fork":false,"pushed_at":"2020-05-14T16:14:36.000Z","size":213,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-11T19:06:21.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","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/bjorg.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":"2020-05-14T16:14:05.000Z","updated_at":"2024-10-14T05:44:52.000Z","dependencies_parsed_at":"2023-03-11T00:24:49.950Z","dependency_job_id":null,"html_url":"https://github.com/bjorg/BlazorWebSocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bjorg/BlazorWebSocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FBlazorWebSocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FBlazorWebSocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FBlazorWebSocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FBlazorWebSocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjorg","download_url":"https://codeload.github.com/bjorg/BlazorWebSocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorg%2FBlazorWebSocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30240902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"ssl_error","status_checked_at":"2026-03-08T00:55:48.608Z","response_time":53,"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":[],"created_at":"2025-03-05T06:28:57.872Z","updated_at":"2026-03-08T01:34:46.795Z","avatar_url":"https://github.com/bjorg.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blazor WebAssembly with WebSocket\n\nThis repository contains a simple application that that connects to the `wss://echo.websocket.org` to show how WebSocket connectivity works in Blazor WebAssembly.\n\n```cshtml\n@page \"/\"\n@using System.Net.WebSockets\n@using System.Text\n@using System.Threading\n@implements IDisposable\n\n\u003ch1\u003eEcho test\u003c/h1\u003e\n\u003ch3\u003eState: @webSocket.State\u003c/h3\u003e\n\n@if(webSocket.State == WebSocketState.Open) {\n    \u003cform @onsubmit=\"SendMessageAsync\"\u003e\n        Message: \u003cinput @bind=\"@message\" /\u003e\n        \u003cbutton type=\"submit\"\u003eSend\u003c/button\u003e\n    \u003c/form\u003e\n    \u003cpre\u003e@log\u003c/pre\u003e\n}\n\n@code {\n\n    // Sample adapted from https://gist.github.com/SteveSandersonMS/5aaff6b010b0785075b0a08cc1e40e01\n\n    //--- Fields ---\n    CancellationTokenSource disposalTokenSource = new CancellationTokenSource();\n    ClientWebSocket webSocket = new ClientWebSocket();\n    string message = \"Hello, websocket!\";\n    string log = \"\";\n\n    //--- Methods ---\n    protected override async Task OnInitializedAsync() {\n        await webSocket.ConnectAsync(new Uri(\"wss://echo.websocket.org\"), disposalTokenSource.Token);\n        _ = ReceiveLoop();\n    }\n\n    private Task SendMessageAsync() {\n        log += $\"Sending: {message}\\n\";\n        var dataToSend = new ArraySegment\u003cbyte\u003e(Encoding.UTF8.GetBytes(message));\n        return webSocket.SendAsync(dataToSend, WebSocketMessageType.Text, true, disposalTokenSource.Token);\n    }\n\n    private async Task ReceiveLoop() {\n        var buffer = new ArraySegment\u003cbyte\u003e(new byte[1024]);\n        while(!disposalTokenSource.IsCancellationRequested) {\n\n            // Note that the received block might only be part of a larger message. If this applies in your scenario,\n            // check the received.EndOfMessage and consider buffering the blocks until that property is true.\n            // Or use a higher-level library such as SignalR.\n            var received = await webSocket.ReceiveAsync(buffer, disposalTokenSource.Token);\n            var receivedAsText = Encoding.UTF8.GetString(buffer.Array, 0, received.Count);\n            log += $\"Received: {receivedAsText}\\n\";\n            StateHasChanged();\n        }\n    }\n\n    public void Dispose() {\n        disposalTokenSource.Cancel();\n        _ = webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, \"Bye\", CancellationToken.None);\n    }\n}\n```\n\n## License\n\n\u003e Licensed under the Apache License, Version 2.0 (the \"License\");\n\u003e you may not use this file except in compliance with the License.\n\u003e You may obtain a copy of the License at\n\u003e\n\u003e http://www.apache.org/licenses/LICENSE-2.0\n\u003e\n\u003e Unless required by applicable law or agreed to in writing, software\n\u003e distributed under the License is distributed on an \"AS IS\" BASIS,\n\u003e WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\u003e See the License for the specific language governing permissions and\n\u003e limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fblazorwebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjorg%2Fblazorwebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorg%2Fblazorwebsocket/lists"}