dotnet posts
Network Utility Methods Part 2: Retrieving Local and Public IP Addresses

Network Utility Methods Part 2: Retrieving Local and Public IP Addresses

Mar 16 2018 — Have you ever wondered what is the correct way to determine either the local or public IP address of your PC? In this post, I explore various methods using built-in classes from the .NET Core framework. I attempt to determine my public/private IP address without the assistance of an external service, in order to eliminate any dependencies.

Network Utility Methods Part 1: Parsing IP Addresses, Handling CIDR Ranges and Netmasks

Network Utility Methods Part 1: Parsing IP Addresses, Handling CIDR Ranges and Netmasks

Feb 24 2018 — Parsing things from text is like death and taxes, it is an absolute certainty that there will be a requirement requiring you to accept a blob of text as an input, wave a magic wand, and voila! You produce a beautiful object as the output of your function. In this post, I demonstrate how to parse IPv4 addresses from text (single or all IPs in text), as well as additional helper methods that work with IP addresses.

Task-based Socket Extension Methods (C# TPL)

Task-based Socket Extension Methods (C# TPL)

Feb 04 2018 — The Task-based Asynchronous Pattern (TAP) is the recommended way to write asynchronous code for .NET applications. As I explained in my last post, TAP is intended to replace the Asynchronous Programming Model (APM) and the Event-based Asynchronous Pattern (EAP), however many classes in the .NET framework still use these older patterns. Fortunately, these can be turned into TAP-style “awaitable” methods with relative ease. By doing so, you reap the benefits that come from working with Task (and Task) objects. In this post, I will convert a set of APM-style methods from the System.Net.Sockets namespace to TAP methods and provide an end-to-end example of how to use them in a generic TCP socket server.

Asynchronous Programming Best Practices in C#

Asynchronous Programming Best Practices in C#

Jan 29 2018 — Do the acronyms APM, EAP, and TAP mean anything to you? Have you ever wondered why there appears to be multiple redundant implementations of the same method in the .NET Framework? If so, you’ve come to the right place. I’ll try and explain why Microsoft felt the need to create three entirely distinct asynchronous programming patterns within the .NET framework and provide a few best practices to follow when writing asynchronous C# code.