Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidfowl/streamer
JSON RPC over any bidirectional stream
https://github.com/davidfowl/streamer
Last synced: about 2 months ago
JSON representation
JSON RPC over any bidirectional stream
- Host: GitHub
- URL: https://github.com/davidfowl/streamer
- Owner: davidfowl
- License: mit
- Created: 2014-02-13T05:02:19.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-02-07T15:16:19.000Z (almost 9 years ago)
- Last Synced: 2024-10-15T05:28:15.278Z (2 months ago)
- Language: C#
- Homepage:
- Size: 22.5 KB
- Stars: 44
- Watchers: 6
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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
```C#
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
```C#
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("Increment");
```## Typed Clients
```C#
public interface IAdder
{
Task 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();// Invoke a method and get a result
var result = await adder.Increment(0);
```