NetDisco 1.0.2
See the version list below for details.
dotnet add package NetDisco --version 1.0.2
NuGet\Install-Package NetDisco -Version 1.0.2
<PackageReference Include="NetDisco" Version="1.0.2" />
paket add NetDisco --version 1.0.2
#r "nuget: NetDisco, 1.0.2"
// Install NetDisco as a Cake Addin #addin nuget:?package=NetDisco&version=1.0.2 // Install NetDisco as a Cake Tool #tool nuget:?package=NetDisco&version=1.0.2
NetDisco
A .Net Standard library for creating auto-discoverable servers and clients.
Feedback
This project is currently a MVP. Please reach out if you find it useful and esspecially if you have any suggestions.
Getting Started
Create a Object Model library
This is where we'll define the object model to share between the server and client projects.
IMPORTANT: The requests and responses are send over the network using JSON serialization.
- Create a new Class Library project
- Add a class that will be the request object
public class Request { public string Body { get; set; } }
- Add a class that will be the response objet
public class Response { public string Result { get; set; } }
Create a Server Application
This is where we'll create the auto-discoverable server using the shared object model
- Create a new Console App project
- Install the NetDisco Nuget package
- Add a class that will be the server
- Add the following using
using NetDisco;
- Add the
AutoDiscoverableServer<Request, Response>
base class - Implement the required members Name, Address, Port, HandleError, and ProcessRequest
public class Server : AutoDiscoverableServer<Request, Response> { public Server(string name, IPAddress address, int port) { _Name = name; _Address = address; _Port = port; } private string _Name = string.Empty; public override string Name => _Name; private IPAddress _Address = IPAddress.None; public override IPAddress Address => _Address; private int _Port = 0; public override int Port => _Port; protected override Response HandleError(Request request, Exception error) { // Log the error message and build a response. var result = string.Format("Error processing the request. Error: {0}", error); return new Response { Result = result }; } protected override Response ProcessRequest(Request request) { // Do work with the request and build a response. var result = string.Format("Server received the request: Body: {0}", request.Body); return new Response { Result = result }; } }
- Add the following using
- Update the Main method of Program.cs to instantiate and start the server
class Program { static void Main(string[] args) { var server = new Server("My Server", IPAddress.Parse("AN_IP_ON_YOUR_MACHINE"), 24516); server.Start(); Console.WriteLine("Server Started: {0}", server); Console.ReadLine(); } }
Create a Client Application
This is where we'll create the client for the auto-discoverable server using the shared object model
- Create a new Console App project
- Install the NetDisco Nuget package
- Add a class that will be the client
- Add the following using
using NetDisco;
- Add the
AutoDiscoverableClient<Request, Response>
base class - Implement the required members Name and HandleError
public class Client : AutoDiscoverableClient<Request, Response> { public Client(string name) { _Name = name; } private string _Name = string.Empty; public override string Name => _Name; protected override Response HandleError(Request request, Exception error) { // Log the error message and build a response. return new Response { Result = string.Format("Error sending request: {0}", error) }; } public string SendMessage(string message) { return Send(new Request { Body = message })?.Result; } }
- Add the following using
- Update the Main method of Program.cs to instantiate the client, send a message, output the response
class Program { static void Main(string[] args) { // This name needs to match the name of the server var client = new Client("My Server"); var reply = client.SendMessage("Hello Auto Discovered World!"); Console.WriteLine(reply); Console.ReadLine(); } }
Watch it Work
- Run the server without debugging
- Run the client and watch it auto-discover the server, send a message and write the response from the server.
- Close the client and server applications
- Change the port and or IP address of the server
- Repeat steps 1 and 2 of this section
Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- log4net (>= 2.0.14)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.2
Upgraded log4net and Newtonsoft.Json to the latest
1.0.1
Added XML Documentation
1.0.0
Initial Release