Skip to content

davidfowl/Streamer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Streamer

RPC over a network should be simpler so here you go. Streamer offers a simple API for RPC over any bidirectional stream.

NuGet

Install-Package Streamer

Server

var server = new TcpListener(IPAddress.Loopback, 1335);
server.Start();

while (true)
{
    var client = await server.AcceptTcpClientAsync();

    // Create a channel to communicate with the client
    var channel = Channel.CreateServer(client.GetStream());

    // Bind the handler that will handle callbacks
    channel.Bind(new Handler());
}


public class Handler
{
    public int Increment(int value)
    {
        Console.WriteLine("Received " + value);

        return value + 1;
    }
}

Client

var client = new TcpClient();
await client.ConnectAsync(IPAddress.Loopback, 1335);

// Create a channel so we can communicate with the server
var channel = Channel.CreateClient(client.GetStream());

// Invoke a method and get a result
var result = await channel.Invoke<int>("Increment");

Typed Clients

public interface IAdder
{
    Task<int> Increment(int value);
}

var client = new TcpClient();
await client.ConnectAsync(IPAddress.Loopback, 1335);

// Create a channel so we can communicate with the server
var channel = new Channel(client.GetStream());

// Create a proxy to the adder interface
var adder = channel.As<IAdder>();

// Invoke a method and get a result
var result = await adder.Increment(0);

About

JSON RPC over any bidirectional stream

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages