Guest User

References and Documentation

a guest
Jan 6th, 2026
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.07 KB | None | 0 0
  1. **Socket Class (Primary Reference)**
  2. | Resource | URL |
  3. |----------|-----|
  4. | Socket API Reference | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=net-10.0 |
  5. | Socket Overview | https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-net-sockets-socket |
  6. | ConnectAsync | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.connectasync?view=net-9.0 |
  7. | SendAsync | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.sendasync?view=net-8.0 |
  8. | ReceiveAsync | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receiveasync?view=net-8.0 |
  9. | Complete Socket Services Tutorial | https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/sockets/socket-services |
  10.  
  11. **TcpClient/TcpListener (Higher-Level APIs)**
  12. | Resource | URL |
  13. |----------|-----|
  14. | TcpClient API | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient?view=net-9.0 |
  15. | TcpListener API | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=net-10.0 |
  16. | TCP Classes Tutorial | https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/sockets/tcp-classes |
  17. | AcceptTcpClientAsync | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener.accepttcpclientasync?view=net-9.0 |
  18. | NetworkStream API | https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream?view=net-10.0 |
  19.  
  20. **Critical .NET 8 performance improvements** are documented in Stephen Toub's annual deep-dive at https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-8/ — a **200+ page** analysis covering JIT optimizations, async improvements, and networking enhancements. The networking-specific improvements are covered at https://devblogs.microsoft.com/dotnet/dotnet-8-networking-improvements/.
  21.  
  22. ## ValueTask versus Task for networking code
  23.  
  24. For high-performance networking, understanding when to use `ValueTask` is essential. Socket methods like `ReceiveAsync` now return `ValueTask<int>` for `Memory<byte>` overloads [Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socket.receiveasync?view=net-8.0) because network operations often complete synchronously when data is already buffered.
  25.  
  26. | Resource | URL |
  27. |----------|-----|
  28. | ValueTask<T> API | https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask-1?view=net-9.0 |
  29. | CA2012: Use ValueTasks Correctly | https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2012 |
  30. | Understanding Task vs ValueTask (Video) | https://learn.microsoft.com/en-us/shows/on-dotnet/understanding-how-to-use-task-and-valuetask |
  31. | ConfigureAwait FAQ | https://devblogs.microsoft.com/dotnet/configureawait-faq/ |
  32.  
  33. **Key constraints**: ValueTask can only be awaited once, cannot be stored, and should not be used with combinators like `Task.WhenAll`. The official guidance states that `Task` remains the default choice — only use `ValueTask` when performance analysis proves worthwhile.
  34.  
  35. ## System.Threading.Channels for producer-consumer patterns
  36.  
  37. Channels provide the ideal abstraction for networking code that needs to decouple message production from consumption. They handle backpressure elegantly and are optimized for high-throughput scenarios.
  38.  
  39. | Resource | URL |
  40. |----------|-----|
  41. | **Channels Conceptual Guide** | https://learn.microsoft.com/en-us/dotnet/core/extensions/channels |
  42. | Channel Factory Methods | https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channel?view=net-8.0 |
  43. | BoundedChannelOptions | https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.boundedchanneloptions?view=net-8.0 |
  44. | ChannelReader<T> | https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channelreader-1?view=net-8.0 |
  45. | ChannelWriter<T> | https://learn.microsoft.com/en-us/dotnet/api/system.threading.channels.channelwriter-1?view=net-8.0 |
  46. | **Stephen Toub's Introduction** | https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/ |
  47.  
  48. Stephen Toub's blog post is the definitive resource, explaining `SingleReader`/`SingleWriter` optimizations that eliminate locking overhead when only one consumer or producer exists [Microsoft](https://devblogs.microsoft.com/dotnet/an-introduction-to-system-threading-channels/) — critical for networking scenarios where a single receive loop processes incoming data.
  49.  
  50. ## Concurrency primitives for flow control
  51.  
  52. | Resource | URL |
  53. |----------|-----|
  54. | SemaphoreSlim (async locking) | https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim?view=net-8.0 |
  55. | SemaphoreSlim.WaitAsync | https://learn.microsoft.com/en-us/dotnet/api/system.threading.semaphoreslim.waitasync?view=net-9.0 |
  56. | Semaphore Conceptual Guide | https://learn.microsoft.com/en-us/dotnet/standard/threading/semaphore-and-semaphoreslim |
  57. | ConcurrentDictionary<K,V> | https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2?view=net-8.0 |
  58. | GetOrAdd Method | https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd?view=net-8.0 |
  59. | **David Fowler's Async Guidance** | https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md |
  60.  
  61. David Fowler's GitHub guidance document is **essential reading** — it covers async locking with `SemaphoreSlim`, common ConcurrentDictionary pitfalls, and patterns that the ASP.NET Core team uses in production.
  62.  
  63. ## Binary serialization with BinaryPrimitives and Span<T>
  64.  
  65. For protocol implementations requiring explicit endianness control, `BinaryPrimitives` provides zero-allocation reads and writes directly to spans — far superior to the older `BitConverter` class.
  66.  
  67. | Resource | URL |
  68. |----------|-----|
  69. | **BinaryPrimitives Class** | https://learn.microsoft.com/en-us/dotnet/api/system.buffers.binary.binaryprimitives?view=net-8.0 |
  70. | ReadInt32BigEndian | https://learn.microsoft.com/en-us/dotnet/api/system.buffers.binary.binaryprimitives.readint32bigendian?view=net-8.0 |
  71. | WriteInt32BigEndian | https://learn.microsoft.com/en-us/dotnet/api/system.buffers.binary.binaryprimitives.writeint32bigendian?view=net-8.0 |
  72. | Span<T> API | https://learn.microsoft.com/en-us/dotnet/api/system.span-1?view=net-8.0 |
  73. | Memory<T> API | https://learn.microsoft.com/en-us/dotnet/api/system.memory-1?view=net-8.0 |
  74. | **Memory/Span Usage Guidelines** | https://learn.microsoft.com/en-us/dotnet/standard/memory-and-spans/memory-t-usage-guidelines |
  75. | ArrayPool<T> | https://learn.microsoft.com/en-us/dotnet/api/system.buffers.arraypool-1?view=net-8.0 |
  76. | SequenceReader<T> | https://learn.microsoft.com/en-us/dotnet/api/system.buffers.sequencereader-1?view=net-8.0 |
  77.  
  78. **Stephen Toub's "All About Span"** [Microsoft Learn](https://learn.microsoft.com/en-us/archive/msdn-magazine/authors/stephen_toub) [Microsoft Docs](https://docs.microsoft.com/de-de/archive/msdn-magazine/authors/stephen_toub) at https://learn.microsoft.com/en-us/archive/msdn-magazine/2018/january/csharp-all-about-span-exploring-a-new-net-mainstay remains the foundational article explaining Span's design, stack-only constraints, and performance characteristics. [Microsoft Learn](https://learn.microsoft.com/en-us/archive/msdn-magazine/authors/stephen_toub)
  79.  
  80. ## System.IO.Pipelines for high-performance I/O
  81.  
  82. Pipelines represent the modern approach to high-performance networking in .NET, providing built-in backpressure, buffer pooling, and efficient handling of incomplete reads. [Microsoft](https://devblogs.microsoft.com/dotnet/author/davifowl/)
  83.  
  84. | Resource | URL |
  85. |----------|-----|
  86. | **Pipelines Guide** | https://learn.microsoft.com/en-us/dotnet/standard/io/pipelines |
  87. | Pipe Class | https://learn.microsoft.com/en-us/dotnet/api/system.io.pipelines.pipe?view=net-8.0 |
  88. | PipeReader | https://learn.microsoft.com/en-us/dotnet/api/system.io.pipelines.pipereader?view=net-8.0 |
  89. | PipeWriter | https://learn.microsoft.com/en-us/dotnet/api/system.io.pipelines.pipewriter?view=net-8.0 |
  90. | Work with Buffers | https://learn.microsoft.com/en-us/dotnet/standard/io/buffers |
  91. | **David Fowler's Pipelines Blog** | https://devblogs.microsoft.com/dotnet/system-io-pipelines-high-performance-io-in-net/ |
  92.  
  93. ## Protocol design RFCs and standards
  94.  
  95. Understanding reliable transport protocols requires studying the original specifications. **RFC 9293** is the modern consolidated TCP specification that obsoletes the original RFC 793.
  96.  
  97. **TCP and Reliable Delivery**
  98. | RFC | URL | Key Content |
  99. |-----|-----|-------------|
  100. | **RFC 9293 (TCP, 2022)** | https://www.rfc-editor.org/rfc/rfc9293.html | Sequence numbers, ACKs, state machine, flow control |
  101. | RFC 793 (Original TCP) | https://www.rfc-editor.org/rfc/rfc793.html | Foundational design philosophy, state diagrams |
  102. | **RFC 6298 (RTO Computation)** | https://www.rfc-editor.org/rfc/rfc6298.html | Retransmission timer, exponential backoff algorithm |
  103. | RFC 5681 (Congestion Control) | https://www.rfc-editor.org/rfc/rfc5681.html | Slow start, fast retransmit, duplicate ACK handling |
  104.  
  105. **Selective Acknowledgments**
  106. | RFC | URL | Key Content |
  107. |-----|-----|-------------|
  108. | **RFC 2018 (TCP SACK)** | https://www.rfc-editor.org/rfc/rfc2018.html | SACK option format, block ranges |
  109. | RFC 6675 (SACK Loss Recovery) | https://www.rfc-editor.org/rfc/rfc6675.html | Scoreboard data structure, conservative recovery |
  110. | **RFC 4960 (SCTP)** | https://www.rfc-editor.org/rfc/rfc4960.html | Cleaner SACK model, TSN-based acknowledgment |
  111.  
  112. **Modern Protocol Patterns (QUIC)**
  113. | RFC | URL | Key Content |
  114. |-----|-----|-------------|
  115. | **RFC 9000 (QUIC Transport)** | https://www.rfc-editor.org/rfc/rfc9000.html | Streams, flow control, framing, connection migration |
  116. | **RFC 9002 (QUIC Loss Detection)** | https://www.rfc-editor.org/rfc/rfc9002.pdf | PTO mechanism, modern exponential backoff |
  117. | RFC 9292 (Binary HTTP) | https://www.rfc-editor.org/rfc/rfc9292.html | Length-prefixed framing example |
  118.  
  119. **RFC 9002** is particularly valuable for modern implementations — it describes QUIC's probe timeout mechanism, which is more sophisticated than TCP's RTO computation.
  120.  
  121. ## Length-prefixed framing and message boundaries
  122.  
  123. TCP provides a byte stream without message boundaries. [CodeProject](https://www.codeproject.com/Articles/37496/TCP-IP-Protocol-Design-Message-Framing) Stephen Cleary's articles explain why framing is necessary and how to implement it:
  124.  
  125. | Resource | URL |
  126. |----------|-----|
  127. | **Message Framing Explanation** | https://blog.stephencleary.com/2009/04/message-framing.html |
  128. | Length-Prefix Implementation | https://blog.stephencleary.com/2009/04/sample-code-length-prefix-message.html |
  129.  
  130. ## State machine patterns in C#
  131.  
  132. | Resource | URL |
  133. |----------|-----|
  134. | Records Reference | https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record |
  135. | Record Structs (C# 10) | https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/record-structs |
  136. | **Enum Design Guidelines** | https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/enum |
  137. | Pattern Matching | https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns |
  138. | Switch Expressions | https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/switch-expression |
  139. | Enumeration Classes Pattern | https://learn.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types |
  140.  
  141. ## Real-world reference: Kestrel socket transport
  142.  
  143. ASP.NET Core's Kestrel web server provides production-grade socket handling code that demonstrates these patterns in practice:
  144.  
  145. | File | URL |
  146. |------|-----|
  147. | **SocketConnection.cs** | https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Transport.Sockets/src/Internal/SocketConnection.cs |
  148. | SocketConnectionListener.cs | https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs |
  149. | SocketTransportOptions.cs | https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Transport.Sockets/src/SocketTransportOptions.cs |
  150. | Transport.Sockets Directory | https://github.com/dotnet/aspnetcore/tree/main/src/Servers/Kestrel/Transport.Sockets/src |
  151.  
  152. `SocketConnection.cs` is the **primary reference** — it demonstrates duplex pipe setup, receive/send loops, shutdown handling, and proper connection lifecycle management.
  153.  
  154. ## Testing async networking code
  155.  
  156. **.NET 8 introduced TimeProvider** — an official abstraction for time [Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/standard/datetime/timeprovider-overview) that replaces custom `ISystemClock` implementations and enables deterministic testing of timeout logic.
  157.  
  158. | Resource | URL |
  159. |----------|-----|
  160. | **TimeProvider Overview** | https://learn.microsoft.com/en-us/dotnet/standard/datetime/timeprovider-overview |
  161. | TimeProvider API | https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider?view=net-8.0 |
  162. | FakeTimeProvider | https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.time.testing.faketimeprovider?view=net-9.0-pp |
  163. | NuGet Package | https://www.nuget.org/packages/Microsoft.Extensions.TimeProvider.Testing/ |
  164.  
  165. **Testing Frameworks**
  166. | Resource | URL |
  167. |----------|-----|
  168. | NUnit Async Tests | https://docs.nunit.org/articles/nunit/writing-tests/attributes/test.html |
  169. | xUnit Shared Context | https://xunit.net/docs/shared-context |
  170. | MSTest Lifecycle | https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-writing-tests-lifecycle |
  171. | **Async Unit Testing Guide** | https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/november/async-programming-unit-testing-asynchronous-code |
  172.  
  173. **Chaos Engineering with Polly**
  174. | Resource | URL |
  175. |----------|-----|
  176. | Polly Documentation | https://www.pollydocs.org/ |
  177. | **Chaos Engineering Blog** | https://devblogs.microsoft.com/dotnet/resilience-and-chaos-engineering/ |
  178. | Polly GitHub | https://github.com/App-vNext/Polly |
  179.  
  180. Polly v8.3+ integrates Simmy for fault injection, enabling injection of exceptions, artificial latency, and fake results to test resilience.
  181.  
  182. ## Essential async and disposal patterns
  183.  
  184. | Resource | URL |
  185. |----------|-----|
  186. | **IAsyncDisposable Implementation** | https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync |
  187. | IAsyncDisposable API | https://learn.microsoft.com/en-us/dotnet/api/system.iasyncdisposable?view=net-9.0 |
  188. | **Cancellation Overview** | https://learn.microsoft.com/en-us/dotnet/standard/threading/cancellation-in-managed-threads |
  189. | Linked CancellationTokens | https://learn.microsoft.com/en-us/dotnet/standard/threading/how-to-listen-for-multiple-cancellation-requests |
  190. | CancellationToken Patterns | https://devblogs.microsoft.com/premier-developer/recommended-patterns-for-cancellationtoken/ |
  191. | **Async Best Practices** | https://learn.microsoft.com/en-us/archive/msdn-magazine/2013/march/async-await-best-practices-in-asynchronous-programming |
  192. | TPL Exception Handling | https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/exception-handling-task-parallel-library |
Advertisement
Add Comment
Please, Sign In to add comment