{"id":13432009,"url":"https://github.com/statianzo/Fleck","last_synced_at":"2025-03-16T23:30:23.319Z","repository":{"id":1136039,"uuid":"1014006","full_name":"statianzo/Fleck","owner":"statianzo","description":"C# Websocket Implementation","archived":false,"fork":false,"pushed_at":"2024-07-03T08:18:44.000Z","size":4772,"stargazers_count":2358,"open_issues_count":81,"forks_count":589,"subscribers_count":133,"default_branch":"master","last_synced_at":"2025-03-13T04:01:43.518Z","etag":null,"topics":["c-sharp","dot-net","hacktoberfest","websocket"],"latest_commit_sha":null,"homepage":"","language":"C#","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/statianzo.png","metadata":{"files":{"readme":"readme.markdown","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}},"created_at":"2010-10-22T02:35:09.000Z","updated_at":"2025-03-12T02:53:03.000Z","dependencies_parsed_at":"2022-08-06T10:15:32.029Z","dependency_job_id":"d290145f-2d92-41f7-84b7-acd7abd04aad","html_url":"https://github.com/statianzo/Fleck","commit_stats":{"total_commits":207,"total_committers":36,"mean_commits":5.75,"dds":"0.40096618357487923","last_synced_commit":"45672e0781974bb04dbad1b94320756a33c60a6d"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2FFleck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2FFleck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2FFleck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statianzo%2FFleck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statianzo","download_url":"https://codeload.github.com/statianzo/Fleck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243949729,"owners_count":20373650,"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","dot-net","hacktoberfest","websocket"],"created_at":"2024-07-31T02:01:07.814Z","updated_at":"2025-03-16T23:30:23.310Z","avatar_url":"https://github.com/statianzo.png","language":"C#","readme":"Fleck\r\n===\r\n\r\n[![Build status](https://ci.appveyor.com/api/projects/status/k0s8hq5y4emak5j3/branch/master?svg=true)](https://ci.appveyor.com/project/statianzo/fleck/branch/master) [![NuGet](https://img.shields.io/nuget/v/Fleck.svg)](https://www.nuget.org/packages/Fleck/)\r\n\r\nFleck is a WebSocket server implementation in C#. Branched from the\r\n[Nugget][nugget] project, Fleck requires no inheritance, container, or\r\nadditional references.\r\n\r\nFleck has no dependency on `HttpListener` or `HTTP.sys` meaning that it\r\nwill work on Windows 7 and Server 2008 hosts. [WebSocket Remarks - Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.websocket?redirectedfrom=MSDN\u0026view=netframework-4.5#remarks)\r\n\r\nExample\r\n---\r\n\r\nThe following is an example that will echo to a client.\r\n\r\n```c#\r\n\r\nvar server = new WebSocketServer(\"ws://0.0.0.0:8181\");\r\nserver.Start(socket =\u003e\r\n{\r\n  socket.OnOpen = () =\u003e Console.WriteLine(\"Open!\");\r\n  socket.OnClose = () =\u003e Console.WriteLine(\"Close!\");\r\n  socket.OnMessage = message =\u003e socket.Send(message);\r\n});\r\n        \r\n```\r\n\r\nSupported WebSocket Versions\r\n---\r\n\r\nFleck supports several WebSocket versions of modern web browsers\r\n\r\n- Hixie-Draft-76/Hybi-00 (Safari 5, Chrome \u003c 14, Firefox 4 (when enabled))\r\n- Hybi-07 (Firefox 6)\r\n- Hybi-10 (Chrome 14-16, Firefox 7)\r\n- Hybi-13 (Chrome 17+, Firefox 11+, Safari 6+, Edge 13+(?))\r\n\r\nSecure WebSockets (wss://)\r\n---\r\n\r\nEnabling secure connections requires two things: using the scheme `wss` instead\r\nof `ws`, and pointing Fleck to an x509 certificate containing a public and\r\nprivate key\r\n\r\n```cs\r\nvar server = new WebSocketServer(\"wss://0.0.0.0:8431\");\r\nserver.Certificate = new X509Certificate2(\"MyCert.pfx\");\r\nserver.Start(socket =\u003e\r\n{\r\n  //...use as normal\r\n});\r\n```\r\n\r\nHaving issues making a certificate? See this\r\n[guide to creating an x509](https://github.com/statianzo/Fleck/issues/214#issuecomment-364413879)\r\nby [@AdrianBathurst](https://github.com/AdrianBathurst)\r\n\r\nSubProtocol Negotiation\r\n---\r\n\r\nTo enable negotiation of subprotocols, specify the supported protocols on\r\nthe `WebSocketServer.SupportedSubProtocols` property. The negotiated\r\nsubprotocol will be available on the socket's `ConnectionInfo.NegotiatedSubProtocol`.\r\n\r\nIf no supported subprotocols are found on the client request (the\r\nSec-WebSocket-Protocol header), the connection will be closed.\r\n\r\n```cs\r\nvar server = new WebSocketServer(\"ws://0.0.0.0:8181\");\r\nserver.SupportedSubProtocols = new []{ \"superchat\", \"chat\" };\r\nserver.Start(socket =\u003e\r\n{\r\n  //socket.ConnectionInfo.NegotiatedSubProtocol is populated\r\n});\r\n```\r\n\r\nCustom Logging\r\n---\r\n\r\nFleck can log into Log4Net or any other third party logging system. Just override the `FleckLog.LogAction` property with the desired behavior.\r\n\r\n```cs\r\nILog logger = LogManager.GetLogger(typeof(FleckLog));\r\n\r\nFleckLog.LogAction = (level, message, ex) =\u003e {\r\n  switch(level) {\r\n    case LogLevel.Debug:\r\n      logger.Debug(message, ex);\r\n      break;\r\n    case LogLevel.Error:\r\n      logger.Error(message, ex);\r\n      break;\r\n    case LogLevel.Warn:\r\n      logger.Warn(message, ex);\r\n      break;\r\n    default:\r\n      logger.Info(message, ex);\r\n      break;\r\n  }\r\n};\r\n\r\n```\r\n\r\nDisable Nagle's Algorithm\r\n---\r\n\r\nSet `NoDelay` to `true` on the `WebSocketConnection.ListenerSocket`\r\n\r\n```cs\r\nvar server = new WebSocketServer(\"ws://0.0.0.0:8181\");\r\nserver.ListenerSocket.NoDelay = true;\r\nserver.Start(socket =\u003e\r\n{\r\n  //Child connections will not use Nagle's Algorithm\r\n});\r\n```\r\n\r\nAuto Restart After Listen Error\r\n---\r\n\r\nSet `RestartAfterListenError` to `true` on the `WebSocketConnection`\r\n\r\n```cs\r\nvar server = new WebSocketServer(\"ws://0.0.0.0:8181\");\r\nserver.RestartAfterListenError = true;\r\nserver.Start(socket =\u003e\r\n{\r\n  //...use as normal\r\n});\r\n```\r\n\r\n[nugget]: http://nugget.codeplex.com/ \r\n","funding_links":[],"categories":["Frameworks, Libraries and Tools","C#","C# #","Libraries, Frameworks and Tools","C\\#","框架, 库和工具","WebSocket"],"sub_categories":["Web Socket"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatianzo%2FFleck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatianzo%2FFleck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatianzo%2FFleck/lists"}