Fleck.Next
1.2.3
dotnet add package Fleck.Next --version 1.2.3
NuGet\Install-Package Fleck.Next -Version 1.2.3
<PackageReference Include="Fleck.Next" Version="1.2.3" />
<PackageVersion Include="Fleck.Next" Version="1.2.3" />
<PackageReference Include="Fleck.Next" />
paket add Fleck.Next --version 1.2.3
#r "nuget: Fleck.Next, 1.2.3"
#:package Fleck.Next@1.2.3
#addin nuget:?package=Fleck.Next&version=1.2.3
#tool nuget:?package=Fleck.Next&version=1.2.3
Fleck
Fleck is a WebSocket server implementation in C#. Branched from the Nugget project, Fleck requires no inheritance, container, or additional references.
Fleck has no dependency on HttpListener or HTTP.sys meaning that it
will work on Windows 7 and Server 2008 hosts. WebSocket Remarks - Microsoft Docs
Example
The following is an example that will echo to a client.
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!");
socket.OnClose = () => Console.WriteLine("Close!");
socket.OnMessage = message => socket.Send(message);
});
Supported WebSocket Versions
Fleck supports several WebSocket versions of modern web browsers
- Hixie-Draft-76/Hybi-00 (Safari 5, Chrome < 14, Firefox 4 (when enabled))
- Hybi-07 (Firefox 6)
- Hybi-10 (Chrome 14-16, Firefox 7)
- Hybi-13 (Chrome 17+, Firefox 11+, Safari 6+, Edge 13+(?))
Secure WebSockets (wss://)
Enabling secure connections requires two things: using the scheme wss instead
of ws, and pointing Fleck to an x509 certificate containing a public and
private key
var server = new WebSocketServer("wss://0.0.0.0:8431");
server.Certificate = new X509Certificate2("MyCert.pfx");
server.Start(socket =>
{
//...use as normal
});
Having issues making a certificate? See this guide to creating an x509 by @AdrianBathurst
SubProtocol Negotiation
To enable negotiation of subprotocols, specify the supported protocols on
the WebSocketServer.SupportedSubProtocols property. The negotiated
subprotocol will be available on the socket's ConnectionInfo.NegotiatedSubProtocol.
If no supported subprotocols are found on the client request (the Sec-WebSocket-Protocol header), the connection will be closed.
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.SupportedSubProtocols = new []{ "superchat", "chat" };
server.Start(socket =>
{
//socket.ConnectionInfo.NegotiatedSubProtocol is populated
});
Custom Logging
Fleck can log into Log4Net or any other third party logging system. Just override the FleckLog.LogAction property with the desired behavior.
ILog logger = LogManager.GetLogger(typeof(FleckLog));
FleckLog.LogAction = (level, message, ex) => {
switch(level) {
case LogLevel.Debug:
logger.Debug(message, ex);
break;
case LogLevel.Error:
logger.Error(message, ex);
break;
case LogLevel.Warn:
logger.Warn(message, ex);
break;
default:
logger.Info(message, ex);
break;
}
};
Disable Nagle's Algorithm
Set NoDelay to true on the WebSocketConnection.ListenerSocket
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.ListenerSocket.NoDelay = true;
server.Start(socket =>
{
//Child connections will not use Nagle's Algorithm
});
Auto Restart After Listen Error
Set RestartAfterListenError to true on the WebSocketConnection
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.RestartAfterListenError = true;
server.Start(socket =>
{
//...use as normal
});
Developer
How to install legacy .NET Framework?
# Download the legacy reference assemblies from NuGet
https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies.net40
https://www.nuget.org/packages/Microsoft.NETFramework.ReferenceAssemblies.net45
# Manual install them into following path and then restart your VS
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 is compatible. netcoreapp2.2 is compatible. netcoreapp3.0 is compatible. netcoreapp3.1 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 is compatible. net462 is compatible. net463 was computed. net47 is compatible. net471 is compatible. net472 is compatible. net48 is compatible. net481 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.0
- No dependencies.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 2.2
- No dependencies.
-
.NETCoreApp 3.0
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.6.2
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.7.2
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETFramework 4.8.1
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.