Network Utility Methods Part 2: Retrieving Local and Public IP Addresses (C# .NET Core)

Let’s finish off the NetworkUtilities class from the previous post with a set of methods that retrieve the private (local) and public (external) IP addresses of the local machine. All source files can be downloaded individually as .cs files or as a single zip file containing the entire class at the gist link below: Network Utilities: IP Parsing/Retrieving (C# .NET Core 2.0) [gist.github.com] Retrieve Local IP Address (Requires Internet) The method below, GetLocalIPv4AddressRequiresInternet, retrieves the local IP address, and does so in a fairly clever way (IMHO).... Read More

Network Utility Methods Part 1: Parsing IP Addresses, Handling CIDR Ranges and Netmasks (C# .NET Core 2.0)

While creating the TPL Socket extension methods, I ended up with a library of networking functions and IP address parsing/retrieving methods. If you would like to download individual .cs files or a zip file containing the entire library, you can do so at the github link below: Network Utilities: IP Parsing/Retrieving (C# .NET Core 2.0) [gist.github.com] This library targets the .NET Core 2.0 framework and therefore can be used on Windows, MacOS and any Linux system where the framework is installed.... Read More

Task-based Socket Extension Methods (C# TPL)

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.... Read More

Parallelism and Asynchronous Programming Best Practices in the C# Task Parallel Library (TPL)

C# classes contain a mixture of three asynchronous patterns: Asynchronous Programming Model (APM) uses the IAsyncResult interface and requires async methods to be defined as BeginProcess and EndProcess methods (e.g., BeginSend/EndSend methods for asynchronous Socket send operations). Event-based Asynchronous Pattern (EAP) was introduced with .NET Framework 2.0 and requires that asynchronous method names end with "Async" and uses event types, delegates, and custom EventArgs classes. Task-based Asynchronous pattern (TAP) was introduced in .... Read More