WitCom is a versatile and innovative API designed to simplify client-server communication, offering intuitive interfaces, robust security, and flexible serialization options. With support for multiple transport mechanisms, including WebSocket, TCP, REST, and even Memory-mapped files, it caters to diverse application needs. Its event-driven architecture and customizable components make it an ideal choice for small-scale projects or complex distributed systems where both client and server are implemented with .Net, positioning WitCom as a modern and simple-to-use alternative to WCF and SignalR.
Key Features of WitCom
Simplicity and Native Use: WitCom’s design ensures intuitive implementation. By eliminating the reliance on text-based messaging, lambda functions, or complex expressions, it simplifies the development process, especially for developers transitioning from other frameworks. Its native approach means developers work with familiar tools and paradigms, reducing the learning curve.
Duplex Communication: WitCom excels in enabling full duplex communication, allowing seamless two-way message exchanges between client and server. Built-in event and callback support accommodates a wide array of delegate types, such as PropertyChangedEventHandler. This duplex model is ideal for applications requiring constant interaction, like live updates, synchronized data sharing, or collaborative systems.
Client-Side Proxy Mirrors Server: A defining feature of WitCom is its ability to create a dynamic proxy on the client side that mirrors the interface of the server object. This means that by simply invoking methods or accessing properties on the client’s proxy, you directly interact with the server. Additionally, subscribing to events on the proxy seamlessly triggers server-side events, making the entire client-server communication invisible and effortless for the user. Developers work naturally with the interface, while WitCom handles all underlying communication.
Interface-Driven Architecture: Service interfaces in WitCom are defined using standard .NET interfaces. This promotes strong type safety and allows for the auto-generation of dynamic client-side proxies that act as exact replicas of server-side services, ensuring consistent behavior across the application.
-
Transport Versatility: WitCom supports a variety of transport mechanisms, making it adaptable to a range of scenarios and infrastructures:
- Memory-Mapped Files: Designed for ultra-fast inter-process communication (IPC) on a single machine.
- Named Pipes: Effective for IPC within the same network or machine, supporting multiple clients.
- TCP: Provides robust and reliable communication for distributed systems, making it suitable for large-scale applications.
- WebSocket: Enables efficient, real-time bidirectional communication across web platforms.
- REST: Simplifies interaction with non-.NET clients, providing rapid deployment of RESTful APIs for external integrations.
-
Extensive Customization:
- Full support for generic functions and properties.
- Flexible serialization formats, including JSON and MessagePack.
- Optional security features, such as end-to-end encryption and token-based authorization.
- Developers can override default implementations for highly specific requirements, ensuring the API adapts to unique project demands.
Enhanced Security: Encryption and Authorization
Security lies at the heart of WitCom’s design, providing robust mechanisms for both encryption and authorization. These capabilities are built on flexible, extensible interfaces, with default implementations included for most standard use cases.
-
End-to-End Encryption: WitCom’s encryption framework ensures secure communication between clients and servers. By default, AES (Advanced Encryption Standard) handles symmetric encryption, while RSA facilitates secure key exchange. This layered security provides:
- Data Confidentiality: Ensures that transmitted data is encrypted and inaccessible to unauthorized entities.
- Integrity: Validates the integrity of the data, preventing tampering during transit.
Developers can implement custom encryption logic by adhering to IEncryptorServer
and IEncryptorClient
interfaces, allowing tailored security measures where required.
Example configuration for enabling encryption:
var server = WitComServerBuilder.Build(options =>
{
options.WithEncryption();
});
var client = WitComClientBuilder.Build(options =>
{
options.WithEncryption();
});
-
Token-Based Authorization: Authorization is seamlessly integrated through token-based systems, providing an additional layer of security. By default, WitCom includes static token validators suitable for most scenarios. Developers can extend functionality by implementing
IAccessTokenValidator
for customized authorization logic, allowing for integration with advanced identity management systems.
Example:
public class AccessTokenValidator : IAccessTokenValidator
{
private readonly string _validToken;
public AccessTokenValidator(string validToken)
{
_validToken = validToken;
}
public bool IsAuthorizationTokenValid(string token)
{
return token == _validToken;
}
}
var server = WitComServerBuilder.Build(options =>
{
options.WithAccessTokenValidator(new AccessTokenValidator("secure-token"));
});
Serialization Options: JSON and MessagePack
Serialization in WitCom is both flexible and efficient, catering to a variety of application needs. Default implementations of serializers are provided, but developers are free to customize by implementing the IMessageSerializer
interface.
- JSON Serialization: JSON is the default format, offering unparalleled readability and widespread support across platforms. Its human-readable format is particularly advantageous during debugging and integration with third-party systems.
Example configuration:
var server = WitComServerBuilder.Build(options =>
{
options.WithJson();
});
var client = WitComClientBuilder.Build(options =>
{
options.WithJson();
});
- MessagePack Serialization: For high-performance applications, MessagePack offers a compact binary serialization format that significantly reduces payload size. This is ideal for bandwidth-sensitive environments or systems with stringent performance requirements.
Example configuration:
var server = WitComServerBuilder.Build(options =>
{
options.WithMessagePack();
});
var client = WitComClientBuilder.Build(options =>
{
options.WithMessagePack();
});
Setting Up WitCom
To illustrate the simplicity of WitCom, consider the following example for setting up a basic service:
- Define the Service Interface:
public interface IExampleService
{
event ExampleServiceEventHandler ProcessingStarted;
event ExampleServiceProgressEventHandler ProgressChanged;
event ExampleServiceProcessingEventHandler ProcessingCompleted;
bool StartProcessing();
void StopProcessing();
}
public delegate void ExampleServiceEventHandler();
public delegate void ExampleServiceProgressEventHandler(double progress);
public delegate void ExampleServiceProcessingEventHandler(ProcessingStatus status);
- Implement the Service:
public class ExampleService : IExampleService
{
public event ExampleServiceEventHandler ProcessingStarted = delegate { };
public event ExampleServiceProgressEventHandler ProgressChanged = delegate { };
public event ExampleServiceProcessingEventHandler ProcessingCompleted = delegate { };
private CancellationTokenSource? _cancellationTokenSource;
public bool StartProcessing()
{
if (_cancellationTokenSource != null) return false;
_cancellationTokenSource = new CancellationTokenSource();
Task.Run(Process);
ProcessingStarted();
return true;
}
public void StopProcessing()
{
_cancellationTokenSource?.Cancel();
}
private void Process()
{
for (int i = 1; i <= 100; i++)
{
if (_cancellationTokenSource?.IsCancellationRequested == true)
{
ProcessingCompleted(ProcessingStatus.Interrupted);
return;
}
ProgressChanged(i);
Thread.Sleep(100);
}
ProcessingCompleted(ProcessingStatus.Success);
}
}
- Configure the Server:
var server = WitComServerBuilder.Build(options =>
{
options.WithService(new ExampleService());
options.WithWebSocket("http://localhost:5000", 10);
options.WithJson();
options.WithEncryption();
});
server.StartWaitingForConnection();
- Connect the Client:
var client = WitComClientBuilder.Build(options =>
{
options.WithWebSocket("ws://localhost:5000");
options.WithJson();
options.WithEncryption();
});
await client.ConnectAsync(TimeSpan.FromSeconds(5), CancellationToken.None);
var service = client.GetService<IExampleService>();
service.ProcessingStarted += () => Console.WriteLine("Processing Started");
service.ProgressChanged += progress => Console.WriteLine($"Progress: {progress}%");
service.ProcessingCompleted += status => Console.WriteLine($"Processing Completed: {status}");
service.StartProcessing();
Examples and GitHub Repository
Explore the complete source code and examples for WitCom:
- GitHub Repository: WitCom
- Inter-Process Communication Examples: Examples/InterProcess
- Multi-Client Service Examples: Examples/Services
WitCom Advantages
- Ease of Use: WitCom eliminates boilerplate code, offering an intuitive setup experience.
- Event-Driven Model: Its event-centric design makes it ideal for reactive and real-time applications.
- Performance: Features like memory-mapped files optimize performance for local IPC scenarios.
- Flexibility: Extensive transport and serialization options cater to diverse use cases.
WitCom empowers developers with a robust yet simple framework for modern client-server communication. By combining powerful features, high performance, and flexibility, it meets the demands of both small-scale and enterprise-level systems. Whether building responsive applications or managing large-scale distributed systems, WitCom represents a significant step forward in .NET communication frameworks.
Top comments (0)