GithubHelp home page GithubHelp logo

chen866 / zerorpc-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ghorsington/zerorpc-dotnet

0.0 1.0 0.0 65 KB

A .NET implementation of ZeroRPC

License: MIT License

C# 98.60% Batchfile 1.40%

zerorpc-dotnet's Introduction

ZeroRPC.NET

Build status

ZeroRPC.NET is a 100% CIL implementation of zerorpc, a simple library for communication and Remote Procedure Calls between distributed processes.

Current version of ZeroRPC.NET supports .NET Framework 3.5 and zerorpc version 3.

The API and core logic were mimicked off zerorpc-node, but modified to work within .NET.

Features

  • Supports .NET 3.5 and Unity
  • Simple API for zeroservices through IService interface
  • Replaceable paramter/return value (de)serializer
  • Synchronous method invoking w/ first-class exceptions
  • Asynchronous invoking through callbacks

Current progress

As of right now, the library is in early beta stage: no official release is available, some useful client-side extensions are missing and not everything has been tested properly yet. However, the library is capable of successfully communicating with zeroservices written in both Python and Node.JS.

Basic example

Server

using ZeroRpc.Net;
using ZeroRpc.Net.ServiceProviders;

namespace ClientExample 
{
    public class ExampleService
    {
        [MethodDocumentation("Echoes the provided string back")]
        public string Echo(string str)
        {
            return str;
        }
    }

    public class ServerShowcase
    {
        public static void Main(string[] args) 
        {
            // ZeroRPC.NET provides a built-in zeroservice that exposes the methods in a provided object
            SimpleWrapperService<ExampleService> service = new SimpleWrapperService<ExampleService>(new ExampleService());

            Server s = new Server(service);

            // Bind the server to local host port 1234
            // The server will provide its zeroservice through TCP
            s.Bind("tcp://127.0.0.1:1234");
            Console.WriteLine("Now serving at 127.0.0.1:1234!");

            // Most errors are fired asynchronously as to not prevent the main data flow
            s.Error += (s, args) => Console.WriteLine(errorArgs.Info);

            // Prevent the console from closing, since Bind returns immediately
            Console.ReadKey();

            // Dispose of the server in the end.
            s.Dispose();
        }
    }
}

Client

using ZeroRpc.Net;

namespace ClientExample 
{
    public class ClientShowcase
    {
        public static void Main(string[] args)
        {
            Client c = new Client();

            // Most errors are fired asynchronously as to not prevent the main data flow
            c.Error += (s, errorArgs) => Console.WriteLine(errorArgs.Info);

            // Connect to a local zeroservice on port 1234 through TCP
            c.Connect("tcp://127.0.0.1:1234");

            // Supports simple synchronous calls with first class exceptions

            try 
            {
                Console.WriteLine(c.Invoke<string>("Echo", "Hello, world!"));
            } catch (RemoteException re) 
            {
                Console.WriteLine($"Error: {re.ErrorName}");
                Console.WriteLine($"Remote stack trace: {re.RemoteStackTrace}");
            }

            // Dispose of the client in the end.
            c.Dispose();
        }
    }
}

zerorpc-dotnet's People

Contributors

ghorsington avatar akeoplus-boris-bocquet avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.