NativeSockets 1.8.0
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Standard 2.1
This package targets .NET Standard 2.1. The package is compatible with this framework or higher.
dotnet add package NativeSockets --version 1.8.0
NuGet\Install-Package NativeSockets -Version 1.8.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NativeSockets" Version="1.8.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NativeSockets" Version="1.8.0" />
<PackageReference Include="NativeSockets" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NativeSockets --version 1.8.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NativeSockets, 1.8.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NativeSockets@1.8.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NativeSockets&version=1.8.0
#tool nuget:?package=NativeSockets&version=1.8.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NativeSockets
A pure C# udp socket library with zero external dependencies.
About
- NativeSockets is a lightweight, cross‑platform library for udp networking.
- It is written entirely in managed C# and does not rely on any third‑party binaries or platform‑specific packages.
- The library provides a consistent API across all supported operating systems, with automatic runtime adaptation to the underlying environment.
Supported Platforms
- Windows
- Linux
- Android
- macOS
- iOS
- tvOS
- watchOS
- visionOS
- FreeBSD
Key Features
- Zero garbage collection pressure
- Pure managed code – No external dependencies to deploy or manage.
- Complete udp support – create, bind, connect, send, receive, and poll sockets.
- Ipv4 and Ipv6 with dual‑mode support.
- Scatter/gather I/O – Efficient vectored send and receive operations.
No External Dependencies
- The library works out‑of‑the‑box on any supported platform.
- There are no additional runtime libraries, native binaries, or platform‑specific packages to install – just add the NuGet package and start using it.
VirtualSocket
A unified socket type that automatically picks the best available backend at runtime:
- When
NativeSocketPal.IsSupportedistrue,VirtualSocketis backed by the native socket implementation. - Otherwise, it transparently falls back to
System.Net.Sockets.Socket.
Key Points
- No manual
NativeSocketPal.Startup/NativeSocketPal.Cleanupcalls are required – the underlying socket subsystem is managed automatically. - The send/receive API mirrors the native socket API and returns an
IoResult(byte count plusSocketError). SocketFlagsare restricted: send operations honor onlyNoneandDontRoute; receive operations honor onlyNoneandPeek. Any other flags are silently ignored.- For vectored receive operations, truncated data is reported as
IoResult.ErrwithSocketError.MessageSize, even when the underlying operation succeeded.
Notes
- On the managed fallback path, a
SendTothat triggers an implicit bind leaves the socket actually bound, butLocalEndPointcannot be queried and throws. This only occurs on .NET 8 and later, because theSendTo(ReadOnlySpan<byte>, SocketFlags, SocketAddress)overload does not set the underlying_rightEndPointfield. In that stateGetNamereports an error even though the datagram was delivered. - The managed fallback path carries the overhead of
System.Net.Sockets; prefer the native backend when performance matters. - When
NativeSocketPal.IsSupportedisfalseand the socket is non-blocking, consider polling withPollorPollFlagsbefore sending or receiving, because frequentSocketError.WouldBlockexceptions have a severe impact on performance.
| 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
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 (2)
Showing the top 2 NuGet packages that depend on NativeSockets:
| Package | Downloads |
|---|---|
|
xENet
ENet reliable UDP networking library with no binary dependencies. |
|
|
ENet-no_binaries
ENet reliable UDP networking library |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on NativeSockets:
| Repository | Stars |
|---|---|
|
Molth/enet-csharp
ENet reliable UDP networking library
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.8.0 | 36 | 10/4/2026 | |
| 1.7.9 | 63 | 10/4/2026 | |
| 1.7.8 | 64 | 10/3/2026 | |
| 1.7.7 | 58 | 9/30/2026 | |
| 1.7.6 | 70 | 9/30/2026 | |
| 1.7.5 | 66 | 9/30/2026 | |
| 1.7.4 | 61 | 9/30/2026 | |
| 1.7.3 | 63 | 9/30/2026 | |
| 1.7.2 | 94 | 9/29/2026 | |
| 1.7.1 | 87 | 9/29/2026 | |
| 1.7.0 | 95 | 9/29/2026 | |
| 1.6.9 | 218 | 9/23/2026 | |
| 1.6.8 | 171 | 9/22/2026 | |
| 1.6.7 | 337 | 9/21/2026 | |
| 1.6.6 | 145 | 9/21/2026 | |
| 1.6.5 | 208 | 9/19/2026 | |
| 1.6.4 | 110 | 9/19/2026 | |
| 1.6.3 | 174 | 9/19/2026 | |
| 1.6.2 | 150 | 9/18/2026 | |
| 1.6.1 | 106 | 9/18/2026 |
Loading failed