SharpChannels.Core 1.0.0-beta

Lightweight communication library for .NET

This is a prerelease version of SharpChannels.Core.
Install-Package SharpChannels.Core -Version 1.0.0-beta
dotnet add package SharpChannels.Core --version 1.0.0-beta
<PackageReference Include="SharpChannels.Core" Version="1.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpChannels.Core --version 1.0.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SharpChannels is a simple and lightweight communication library for .NET.

What?

Two things:

  1. Gives you the higher level entities to use for messaging instead of the byte streams and sockets.
    Namely: channels and messages
  2. Implements well-known messaging scenarios
  • request-response
  • publisher-subscriber
  • service bus

Why?

It is very expensive to develop a reliable server and client (using TCP for example),
implement an application layer protocol for messaging, and then use all this stuff in a communication scenarios, like response to the requestor, broadcasts message to the subscribers etc.

SharpChannels has already done it all.

Use entities which can send and receive messages rather than write the byte sequence to or read it from stream.
It also gives you a seamless switching between transport protocols.

Transports
  • TCP
  • In-process (inside AppDomain)
Security
  • TLS 1.2
Serialization
  • built-in for text messages
  • built-in for binary messages
  • native (using BinaryFormatter class)
  • proto-buf
  • custom user serialization
Other features
  • version based handshake
  • explicit channel closing (as in SCTP)

Usage

Нere is a simple example of request-response messaging using SharpChannels

Server side:

var serializer = new StringMessageSerializer();

var serverCommunication = new TcpCommunication<StringMessage>(
                            new TcpEndpointData(IPAddress.Any, 2000), 
                            serializer);

var server = Scenarios.RequestResponse.SetupServer(serverCommunication)
    .UsingNewClientHandler((sender, a) => { Console.WriteLine("channel opened"); })
    .UsingRequestHandler((sender, a) => 
            { 
                        a.Response = new StringMessage(a.Request.Message.Replace("request", "response")); 
            })
    .UsingChannelClosedHandler((sender, a) => { Console.WriteLine("channel closed"); })
    .Go();

Client side:

var clientCommunication = new TcpCommunication<StringMessage>(
                            new TcpEndpointData(IPAddress.Loopback, 2000), 
                            serializer);

var r = Scenarios.RequestResponse.Requester(clientCommunication);

using (r.Channel)
{
    r.Channel.Open();

    for (int i = 0; i < 100; i++)
    {
        var requestMessage = new StringMessage($"request #{i}");
        Console.WriteLine(requestMessage);

        var responseMessage = r.Request(requestMessage);
        Console.WriteLine(responseMessage);
    }

    r.Channel.Close();
}

SharpChannels is a simple and lightweight communication library for .NET.

What?

Two things:

  1. Gives you the higher level entities to use for messaging instead of the byte streams and sockets.
    Namely: channels and messages
  2. Implements well-known messaging scenarios
  • request-response
  • publisher-subscriber
  • service bus

Why?

It is very expensive to develop a reliable server and client (using TCP for example),
implement an application layer protocol for messaging, and then use all this stuff in a communication scenarios, like response to the requestor, broadcasts message to the subscribers etc.

SharpChannels has already done it all.

Use entities which can send and receive messages rather than write the byte sequence to or read it from stream.
It also gives you a seamless switching between transport protocols.

Transports
  • TCP
  • In-process (inside AppDomain)
Security
  • TLS 1.2
Serialization
  • built-in for text messages
  • built-in for binary messages
  • native (using BinaryFormatter class)
  • proto-buf
  • custom user serialization
Other features
  • version based handshake
  • explicit channel closing (as in SCTP)

Usage

Нere is a simple example of request-response messaging using SharpChannels

Server side:

var serializer = new StringMessageSerializer();

var serverCommunication = new TcpCommunication<StringMessage>(
                            new TcpEndpointData(IPAddress.Any, 2000), 
                            serializer);

var server = Scenarios.RequestResponse.SetupServer(serverCommunication)
    .UsingNewClientHandler((sender, a) => { Console.WriteLine("channel opened"); })
    .UsingRequestHandler((sender, a) => 
            { 
                        a.Response = new StringMessage(a.Request.Message.Replace("request", "response")); 
            })
    .UsingChannelClosedHandler((sender, a) => { Console.WriteLine("channel closed"); })
    .Go();

Client side:

var clientCommunication = new TcpCommunication<StringMessage>(
                            new TcpEndpointData(IPAddress.Loopback, 2000), 
                            serializer);

var r = Scenarios.RequestResponse.Requester(clientCommunication);

using (r.Channel)
{
    r.Channel.Open();

    for (int i = 0; i < 100; i++)
    {
        var requestMessage = new StringMessage($"request #{i}");
        Console.WriteLine(requestMessage);

        var responseMessage = r.Request(requestMessage);
        Console.WriteLine(responseMessage);
    }

    r.Channel.Close();
}

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0-beta 370 1/18/2018