1k0n.NetworkDiscovery 1.0.2.3

dotnet add package 1k0n.NetworkDiscovery --version 1.0.2.3                
NuGet\Install-Package 1k0n.NetworkDiscovery -Version 1.0.2.3                
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="1k0n.NetworkDiscovery" Version="1.0.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add 1k0n.NetworkDiscovery --version 1.0.2.3                
#r "nuget: 1k0n.NetworkDiscovery, 1.0.2.3"                
#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.
// Install 1k0n.NetworkDiscovery as a Cake Addin
#addin nuget:?package=1k0n.NetworkDiscovery&version=1.0.2.3

// Install 1k0n.NetworkDiscovery as a Cake Tool
#tool nuget:?package=1k0n.NetworkDiscovery&version=1.0.2.3                

1k0n Network Discovery

Getting Started

Include the library and decalre a using to the 1k0n.NetworkDiscovery namespace.

 using _1k0n.NetworkDiscovery;

1. Define Request message

This can be any class with a default constructor. The client broadcasts this message when looking for the server.

Fields can be any type serializable to JSON

public class MyDiscoveryRequest
{
	public string? Field1 { get; set; }
	public string? Field2 { get; set; }

	public MyDiscoveryRequest()
	{
	}
}

2. Define Response message

This can be any class with a default constructor. The server will send this back to the client after receiving the request.

Fields can be any type serializable to JSON

public class MyDiscoverResponse
{
	public string? Field1 { get; set; }
	public string? Field2 { get; set; }

	public MyDiscoveryResponse()
	{
	}
}

3. Implement DiscoveryServer

Create a class that inherits from DiscoverServer and override the GenerateResponse method.

public class MyDiscoveryServer : DiscoveryServer<MyDiscoveryRequest, MyDiscoveryResponse>
{
	protected override MyDiscoveryResponse GenerateResponse(MyDiscoveryRequest request)
	{
		var response = new MyDiscoveryResponse();

		...

		return response;
	}
}

The MyDiscoveryRequest class is defined in Step 1.

The MyDiscoveryResponse class is defined in Step 2.

4. Searching for server

The DiscoveryClient class has a static method to discover servers called Search. The Search method returns an IAsyncEnumerable<TResponse?>

DiscoveryClient.Search<TRequest, TResponse>()

DiscoveryClient.Search<TRequest, TResponse>(IPAddress? subnet, int port, TRequest request, CancellationToken token)

Parameters:
  • subnet (IPAddress?): Pass in the subnet to search on. DiscoverySearch will use the default network if null is supplied.
  • port (int): Port to do the search on. This needs to match the port the server is listening on.
  • request (TRequest): This is the request message that is broadcast in search of the server.
  • token (CancellationToken): Use this to cancell the search.
Example:

Searching is demonstrated in the method below.

Searching will stop when either a server responds or the CancellationToken is signaled.

The example method DoSearch can be called on a background thread so ask not to block the UI.

private async Task<MyDiscoveryResponse?> DoSearch(IPAddress? subnet, int discoveryPort, MyDiscoveryRequest request, CancellationToken token)
{
	var searcher = DiscoveryClient.Search<MyDiscoveryRequest, MyDiscoveryResponse>(subnet, discoveryPort, request, token);

	MyDiscoveryResponse? response = null;

	await foreach (var discovery in searcher)
	{
		if (!(discovery is null))
		{
			response = discovery;
			break;
		}

	}

	return response;
}

The MyDiscoveryRequest class is defined in Step 1.

The MyDiscoveryResponse class is defined in Step 2.

Copyright © 2022 John Meyer Jr.

To be used with the 1k0n Network Discovery library.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.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.

Version Downloads Last updated
1.0.2.3 216 12/20/2023
1.0.2.2 207 5/23/2023
1.0.2.1 145 5/17/2023
1.0.2 345 11/13/2022