WatsonMesh 5.0.1
dotnet add package WatsonMesh --version 5.0.1
NuGet\Install-Package WatsonMesh -Version 5.0.1
<PackageReference Include="WatsonMesh" Version="5.0.1" />
paket add WatsonMesh --version 5.0.1
#r "nuget: WatsonMesh, 5.0.1"
// Install WatsonMesh as a Cake Addin #addin nuget:?package=WatsonMesh&version=5.0.1 // Install WatsonMesh as a Cake Tool #tool nuget:?package=WatsonMesh&version=5.0.1
Watson Mesh Networking
A simple C# mesh networking library using TCP (with or without SSL) with integrated framing for reliable transmission and receipt of data amongst multiple nodes.
New in v5.0.x
- Update to latest WatsonTcp
- Migrated from string IP:port methods to GUID
- Migrated to async methods
- Rename enums, add JSON converter details
- Consistent logging headers
- Usings inside of namespace
- Async callback for SyncRequest
- Cancellation token and
ConfigureAwait
What is Watson Mesh?
Watson Mesh is a simple library for mesh networking (all nodes have connections to one another). Instantiate the WatsonMesh
class after defining the mesh network settings in MeshSettings
. Then, add MeshPeer
objects representing the other nodes in the network. Each WatsonMesh
node runs a local server and one client for each defined MeshPeer
. By default, a node will attempt to reconnect to each of the configured peers should the connection become severed.
The network IsHealthy
from a node's perspective if it has established outbound connections to each of its defined peers. Thus, the health of the network is determined by each node from its own viewpoint. The state of inbound connections from other nodes is not considered, but rather its ability to reach out to its peers.
Under the hood, WatsonMesh
relies on WatsonTcp
(see https://github.com/dotnet/WatsonTcp) for framing and reliable delivery.
Test App
Refer to the Test
project for a full working example. Multiple instances can be started with each server listening on a different port. Then add each node as peers on each of the nodes you start.
Local vs External Connections
IMPORTANT
The IP address you specify determines whether or not WatsonMesh will allow external connections.
- If you specify
127.0.0.1
as the IP address, WatsonMesh will only be able to accept connections from within the local host. - To accept connections from other machines:
- Use a specific interface IP address (i.e.
ipconfig
from Command Prompt orifconfig
from Linux shell) - Make sure you create a permit rule on your firewall to allow inbound connections on that port
- Use a specific interface IP address (i.e.
- If you use a port number under 1024, admin privileges will be required
REMINDER If you use 127.0.0.1
as your IP address, WatsonMesh will only be allowed to receive connections from the local machine.
Known Limitations
WatsonMesh will not work in environments where NAT (Network Address Translation) exists in between members of the mesh network.
Example
The following example shows a simple example using byte arrays and without SSL. Make sure you start instances for mesh nodes running on ports 8000, 8001, and 8002. You can use multiple instances of the Test
project to see a more complete example.
using WatsonMesh;
// initialize
MeshNode mesh = new MeshNode(new MeshSettings(), "127.0.0.1", 8000);
// define callbacks and start
mesh.PeerConnected += PeerConnected;
mesh.PeerDisconnected += PeerDisconnected;
mesh.MessageReceived += MessageReceived;
mesh.SyncMessageReceived = SyncMessageReceived;
mesh.Start();
// add peers
mesh.Add(new Peer([guid], "127.0.0.1:8001"));
mesh.Add(new Peer([guid], "127.0.0.1:8002"));
// implement events
static void PeerConnected(object sender, ServerConnectionEventArgs args)
{
Console.WriteLine("Peer " + args.PeerNode.ToString() + " connected");
}
static void PeerDisconnected(object sender, ServerConnectionEventArgs args)
{
Console.WriteLine("Peer " + args.PeerNode.ToString() + " disconnected");
}
static void MessageReceived(object sender, MeshMessageReceivedEventArgs args)
{
Console.WriteLine("Message from " + args.SourceIpPort + ": " + Encoding.UTF8.GetBytes(args.Data));
}
static SyncResponse SyncMessageReceived(MeshMessageReceivedEventArgs args)
{
Console.WriteLine("Message from " + args.SourceIpPort + ": " + Encoding.UTF8.GetBytes(args.Data));
return new SyncResponse(SyncResponseStatus.Success, "Hello back at you!");
}
// send messages
if (!await mesh.Send([guid], "Hello, world!")) { // handle errors }
if (!await mesh.Broadcast("Hello, world!")) { // handle errors }
SyncResponse resp = await mesh.SendAndWait([guid], 5000, "Hello, world!");
Version History
Refer to CHANGELOG.md for a list of changes by version.
Product | Versions 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 is compatible. 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 Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
-
.NETFramework 4.6.2
- System.Text.Json (>= 8.0.1)
- WatsonTcp (>= 6.0.4)
-
.NETFramework 4.8
- System.Text.Json (>= 8.0.1)
- WatsonTcp (>= 6.0.4)
-
net6.0
- System.Text.Json (>= 8.0.1)
- WatsonTcp (>= 6.0.4)
-
net7.0
- System.Text.Json (>= 8.0.1)
- WatsonTcp (>= 6.0.4)
-
net8.0
- System.Text.Json (>= 8.0.1)
- WatsonTcp (>= 6.0.4)
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 |
---|---|---|
5.0.1 | 198 | 1/11/2024 |
4.0.1 | 119 | 1/9/2024 |
4.0.0.2 | 7,827 | 11/12/2021 |
4.0.0.1 | 328 | 11/12/2021 |
4.0.0 | 2,257 | 8/23/2021 |
3.1.0 | 31,001 | 3/24/2020 |
3.0.0 | 19,031 | 2/25/2020 |
2.0.3 | 23,062 | 9/21/2019 |
2.0.2 | 583 | 9/10/2019 |
2.0.0 | 561 | 9/6/2019 |
1.2.7 | 750 | 6/25/2019 |
1.2.6 | 589 | 6/25/2019 |
1.2.2 | 639 | 6/13/2019 |
1.2.1 | 665 | 6/1/2019 |
1.1.4 | 636 | 5/23/2019 |
1.1.3 | 623 | 5/17/2019 |
1.1.1 | 626 | 5/9/2019 |
1.1.0 | 613 | 5/8/2019 |
1.0.8 | 732 | 3/15/2019 |
1.0.7 | 1,012 | 7/8/2018 |
1.0.5 | 1,074 | 6/24/2018 |
1.0.3 | 1,023 | 5/24/2018 |
1.0.2 | 1,044 | 5/13/2018 |
1.0.1.1 | 998 | 5/9/2018 |
1.0.0 | 1,000 | 4/26/2018 |
Dependency update and breaking changes