Newtonsoft.Json (JSON.NET) serialization provider for IpcLibrary. Provides JSON serialization using the popular JSON.NET library. Use this if your project already depends on Newtonsoft.Json or requires its advanced features.
$ dotnet add package IpcLibrary.Serialization.NewtonsoftA production-ready .NET Standard 2.1 library for peer-to-peer inter-process communication on local networks. Enables applications to auto-discover each other and establish secure, direct connections in a mesh network topology with full bidirectional messaging.
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ App A │◄──►│ App B │◄──►│ App C │
│ (Node: A1B2)│ │ (Node: C3D4)│ │ (Node: E5F6)│
└─────────────┘ └─────────────┘ └─────────────┘
▲ ▲ ▲
└───────────────────┼───────────────────┘
▼
UDP Discovery (Port 12345)
TCP Messaging (Dynamic Ports)
Step 1: Install IpcLibrary
dotnet add package IpcLibrary
Step 2: Choose a JSON Serializer
IpcLibrary requires a JSON serialization provider. Choose one:
High-performance, modern JSON serialization:
dotnet add package IpcLibrary.Serialization.SystemTextJson
For projects already using Newtonsoft.Json:
dotnet add package IpcLibrary.Serialization.Newtonsoft
Complete Installation Examples:
# Recommended: With System.Text.Json
dotnet add package IpcLibrary
dotnet add package IpcLibrary.Serialization.SystemTextJson
# Alternative: With JSON.NET
dotnet add package IpcLibrary
dotnet add package IpcLibrary.Serialization.Newtonsoft
Package Info:
using IpcLibrary;
using IpcLibrary.Abstractions.Configuration;
using IpcLibrary.Serialization.SystemTextJson;
// Create JSON serializer
var serializer = new SystemTextJsonSerializer();
// Create and start an IPC node
var node = new IpcNode(serializer);
await node.StartAsync(12345, "shared-auth-key");
// Handle incoming messages
node.TextMessageReceived += (sender, e) => {
Console.WriteLine($"Received from {e.SenderId}: {e.Text}");
};
// Handle peer connections
node.PeerConnected += (sender, e) => {
Console.WriteLine($"Peer {e.PeerInfo.NodeId} connected!");
};
node.PeerDisconnected += (sender, e) => {
Console.WriteLine($"Peer {e.PeerInfo.NodeId} disconnected!");
};
// Send a message to all peers
await node.BroadcastTextAsync("Hello from my application!");
// Send to a specific peer
await node.SendTextAsync("A1B2C3D4", "Direct message");
// Cleanup
await node.StopAsync();
node.Dispose();
using IpcLibrary;
using IpcLibrary.Serialization.Newtonsoft;
// Create JSON serializer
var serializer = new NewtonsoftJsonSerializer();
// Create and start an IPC node
var node = new IpcNode(serializer);
await node.StartAsync(12345, "shared-auth-key");
// ... rest of your code
Create a simple chat app in 5 minutes:
# Create new console app
dotnet new console -n MyChat
cd MyChat
# Install IpcLibrary and serializer from NuGet
dotnet add package IpcLibrary
dotnet add package IpcLibrary.Serialization.SystemTextJson
Replace Program.cs:
using IpcLibrary;
using IpcLibrary.Serialization.SystemTextJson;
var serializer = new SystemTextJsonSerializer();
var node = new IpcNode(serializer);
// Handle incoming messages
node.TextMessageReceived += (sender, e) =>
Console.WriteLine($"[{e.SenderId}]: {e.Text}");
// Handle peer connections
node.PeerConnected += (sender, e) =>
Console.WriteLine($"* {e.PeerInfo.NodeId} joined");
Console.WriteLine($"Starting node {node.NodeId}...");
await node.StartAsync(12345, "my-network");
Console.WriteLine("Ready! Type messages (Ctrl+C to exit)");
// Send messages
while (true)
{
var message = Console.ReadLine();
if (!string.IsNullOrEmpty(message))
await node.BroadcastTextAsync(message);
}
Run multiple instances:
# Terminal 1
dotnet run
# Terminal 2
dotnet run
# They'll discover each other automatically!
That's it! You now have a working peer-to-peer chat application. 🎉
using IpcLibrary.Serialization.SystemTextJson;
var serializer = new SystemTextJsonSerializer();
// Using configuration builder for flexible setup
var config = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(13000) // Custom port to avoid conflicts
.WithConnectionTimeout(10000) // 10 second timeout
.WithDebugLogging(true) // Enable debug logging
.Build();
var node = new IpcNode(serializer);
await node.StartAsync(config, "my-secure-key");
// Network-specific configuration (useful for multiple apps)
var networkConfig = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(13000) // Explicit port for this app
.ForProduction() // Production-ready timeouts
.Build();
// Testing configuration with dynamic ports
var testConfig = IpcConfigurationBuilder.Create()
.ForTesting() // Fast timeouts, OS-assigned port
.Build();
// Send to specific peer
await node.SendTextAsync("A1B2C3D4", "Direct message to specific peer");
// Monitor peer connections
node.PeerConnected += (sender, peerId) =>
Console.WriteLine($"Peer {peerId} joined the network");
node.PeerDisconnected += (sender, peerId) =>
Console.WriteLine($"Peer {peerId} left the network");
// For running multiple IPC networks on same machine
var customerServiceConfig = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(13001) // Customer service port
.Build();
var inventoryConfig = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(13002) // Inventory system port
.Build();
var reportingConfig = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(13003) // Reporting dashboard port
.Build();
IpcLibrary v2.0+ uses abstracted JSON serialization, giving you full control over which JSON library to use. This prevents dependency conflicts and lets you optimize for your specific needs.
Best for: Modern applications, high performance, minimal dependencies
dotnet add package IpcLibrary.Serialization.SystemTextJson
Usage:
using IpcLibrary.Serialization.SystemTextJson;
// Default options (recommended)
var serializer = new SystemTextJsonSerializer();
// Custom options
var options = new System.Text.Json.JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
WriteIndented = false,
// Add your custom settings
};
var customSerializer = new SystemTextJsonSerializer(options);
var node = new IpcNode(serializer);
Pros:
Best for: Projects already using Newtonsoft.Json, legacy compatibility
dotnet add package IpcLibrary.Serialization.Newtonsoft
Usage:
using IpcLibrary.Serialization.Newtonsoft;
// Default settings (recommended)
var serializer = new NewtonsoftJsonSerializer();
// Custom settings
var settings = new Newtonsoft.Json.JsonSerializerSettings
{
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
Formatting = Newtonsoft.Json.Formatting.None,
// Add your custom settings
};
var customSerializer = new NewtonsoftJsonSerializer(settings);
var node = new IpcNode(serializer);
Pros:
You can implement your own serializer by implementing IJsonSerializer:
using IpcLibrary.Abstractions.Serialization;
public class MyCustomSerializer : IJsonSerializer
{
public string Serialize<T>(T value)
{
// Your serialization logic
}
public T? Deserialize<T>(string json) where T : class
{
// Your deserialization logic
}
}
var serializer = new MyCustomSerializer();
var node = new IpcNode(serializer);
IpcLibrary v2.0 introduces one breaking change: the IpcNode constructor now requires an IJsonSerializer parameter.
Step 1: Install a serialization provider
# Choose one:
dotnet add package IpcLibrary.Serialization.SystemTextJson
# OR
dotnet add package IpcLibrary.Serialization.Newtonsoft
Step 2: Update your code
Before (v1.x):
using IpcLibrary;
var node = new IpcNode();
await node.StartAsync(12345, "my-key");
After (v2.0):
using IpcLibrary;
using IpcLibrary.Serialization.SystemTextJson;
var serializer = new SystemTextJsonSerializer();
var node = new IpcNode(serializer);
await node.StartAsync(12345, "my-key");
✅ Functionality: All features work exactly the same
✅ Performance: No performance impact
✅ Wire Protocol: Nodes on v1.x and v2.0 can communicate
✅ Test Coverage: 176/176 tests passing
This change provides:
IpcLibrary/
├── 📁 IpcLibrary.Abstractions/ # Public interfaces and models
├── 📁 IpcLibrary/ # Core implementation
├── 📁 IpcLibrary.Serialization.SystemTextJson/ # System.Text.Json provider
├── 📁 IpcLibrary.Serialization.Newtonsoft/ # JSON.NET provider
├── 📁 IpcLibrary.Tests/ # Fast unit tests (~2-3s)
├── 📁 IpcLibrary.IntegrationTests/ # Network integration tests
├── 📁 IpcLibrary.Demo/ # Example console application
└── 📄 Solution Items/ # Documentation & config
# Fast unit tests only (recommended during development)
dotnet test IpcLibrary.Tests
# OR use the helper script
./run-unit-tests.bat
# Integration tests (network-dependent, slower)
dotnet test IpcLibrary.IntegrationTests
# OR use the helper script
./run-integration-tests.bat
# All tests
dotnet test
# OR use the helper script
./run-all-tests.bat
# Build entire solution
dotnet build
# Build specific project
dotnet build IpcLibrary/IpcLibrary.csproj
// 1. Simple port override
await node.StartAsync(13000, "auth-key"); // Use port 13000
// 2. Configuration builder approach
var config = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(14000)
.Build();
await node.StartAsync(config, "auth-key");
// 3. Dynamic port assignment (testing)
var config = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(0) // Let OS choose available port
.Build();
// 4. Pre-built configurations
var testConfig = IpcConfiguration.CreateTestConfiguration(); // Dynamic ports
var networkConfig = IpcConfiguration.CreateNetworkConfiguration(10); // Port 12010
public class IpcNode : IDisposable
{
// Constructor
public IpcNode(IJsonSerializer jsonSerializer);
// Properties
string NodeId { get; } // 8-character hex ID
NodeStatus Status { get; } // Stopped, Starting, Running
IReadOnlyList<string> ConnectedPeers { get; } // List of connected peer IDs
// Lifecycle Methods
Task StartAsync(int discoveryPort, string secretKey);
Task StartAsync(IpcConfiguration configuration, string secretKey);
Task StopAsync();
void Dispose();
// Messaging Methods
Task SendTextAsync(string targetId, string message);
Task BroadcastTextAsync(string message);
// Events
event EventHandler<PeerConnectedEventArgs> PeerConnected;
event EventHandler<PeerDisconnectedEventArgs> PeerDisconnected;
event EventHandler<TextMessageReceivedEventArgs> TextMessageReceived;
event EventHandler<NodeStatusChangedEventArgs> StatusChanged;
}
public class PeerConnectedEventArgs : EventArgs
{
public PeerInfo PeerInfo { get; }
}
public class PeerDisconnectedEventArgs : EventArgs
{
public PeerInfo PeerInfo { get; }
public string Reason { get; }
}
public class TextMessageReceivedEventArgs : EventArgs
{
public Message Message { get; }
public string SenderId { get; }
public string Text { get; }
public DateTime Timestamp { get; }
}
var config = IpcConfigurationBuilder.Create()
.WithDiscoveryPort(12345)
.WithConnectionTimeout(5000)
.Build();
IpcLibrary.Tests/IpcLibrary.IntegrationTests/✅ All connection establishment tests passing
✅ All disconnect detection tests passing
✅ All message sending/receiving tests passing
✅ All authentication tests passing
✅ All multi-node mesh tests passing
Port Already in Use
# Check what's using port 12345
netstat -an | findstr :12345
Authentication Failures
authKeyConnection Timeouts
Enable detailed logging by setting environment variable:
set IPCLIB_DEBUG=true
git checkout -b feature/amazing-feature)./run-all-tests.bat)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)Run 3 nodes instantly with one command:
.\run-3-nodes.bat
Or start nodes manually:
# Terminal 1 - Alice
dotnet run --project IpcLibrary.Demo -- --name Alice --port 12345 --key mynetwork
# Terminal 2 - Bob
dotnet run --project IpcLibrary.Demo -- --name Bob --port 12345 --key mynetwork
# Terminal 3 - Charlie
dotnet run --project IpcLibrary.Demo -- --name Charlie --port 12345 --key mynetwork
/help Show command list
/peers List connected peers
/send [nodeId] [message] Send to specific peer
/broadcast [message] Send to all peers
[message] Shortcut to broadcast
/history Show message history
/clear Clear screen
/quit Exit application
Node-MC-GAMING> /peers
╔════════════════════════════════╗
║ Connected Peers (2) ║
╚════════════════════════════════╝
● Peer1 (5E4423AF)
● Peer2 (776F5DF3)
Node-MC-GAMING> /broadcast Hello everyone!
➤ Broadcast to 2 peer(s): Hello everyone!
Node-MC-GAMING>
[20:45:32] Peer1: Hi there!
[20:45:35] Peer2: Hello!
See docs/DEMO-GUIDE.md for detailed examples and screenshots.
dotnet add package IpcLibrary
Includes:
dotnet add package IpcLibrary.Abstractions
Includes:
dotnet add package IpcLibrary.Serialization.SystemTextJson
Includes:
dotnet add package IpcLibrary.Serialization.Newtonsoft
Includes:
Both packages include:
Core Library:
Serialization Providers:
This project is licensed under the MIT License - see the LICENSE file for details.
📦 Available on NuGet • 100% test coverage • Flexible JSON • Full feature set • Comprehensive docs • Working demo
# Install IpcLibrary
dotnet add package IpcLibrary
# Choose your JSON serializer
dotnet add package IpcLibrary.Serialization.SystemTextJson
# OR
dotnet add package IpcLibrary.Serialization.Newtonsoft
🌟 Star on GitHub if you find this useful!
💬 Share feedback via GitHub Issues or Discussions
Built with ❤️ for the .NET community