• Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 10 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bi-directional RPC in Go (Golang)

rpc2

GoDoc Build Status

rpc2 is a fork of net/rpc package in the standard library. The main goal is to add bi-directional support to calls. That means server can call the methods of client. This is not possible with net/rpc package. In order to do this it adds a *Client argument to method signatures.

Install

go get github.com/cenkalti/rpc2

Example server

package main

import (
	"fmt"
	"net"

	"github.com/cenkalti/rpc2"
)

type Args struct{ A, B int }
type Reply int

func main() {
	srv := rpc2.NewServer()
	srv.Handle("add", func(client *rpc2.Client, args *Args, reply *Reply) error {

		// Reversed call (server to client)
		var rep Reply
		client.Call("mult", Args{2, 3}, &rep)
		fmt.Println("mult result:", rep)

		*reply = Reply(args.A + args.B)
		return nil
	})

	lis, _ := net.Listen("tcp", "127.0.0.1:5000")
	srv.Accept(lis)
}

Example Client

package main

import (
	"fmt"
	"net"

	"github.com/cenkalti/rpc2"
)

type Args struct{ A, B int }
type Reply int

func main() {
	conn, _ := net.Dial("tcp", "127.0.0.1:5000")

	clt := rpc2.NewClient(conn)
	clt.Handle("mult", func(client *rpc2.Client, args *Args, reply *Reply) error {
		*reply = Reply(args.A * args.B)
		return nil
	})
	go clt.Run()

	var rep Reply
	clt.Call("add", Args{1, 2}, &rep)
	fmt.Println("add result:", rep)
}

More Repositories

1

backoff

⏱ The exponential backoff algorithm in Go
Go
3,369
star
2

rain

🌧 BitTorrent client and library in Go
Go
953
star
3

github-flask

🍾 Flask extension for GitHub API
Python
264
star
4

dalga

⏰ MySQL backed Job Scheduler with a HTTP interface
Go
248
star
5

kuyruk

⚙️ Simple task queue for Python
Python
231
star
6

dominantcolor

Find dominant color in images
Go
119
star
7

pypi-notifier

📨 A web service that monitors your requirements.txt files
Python
100
star
8

putio.py

A python wrapper for put.io APIv2
Python
72
star
9

pyhtml

HTML generation library for Python
Python
70
star
10

tus.py

tus (resumable file upload protocol) client in python
Python
34
star
11

what

A helper for testing output of a process in tests.
Python
24
star
12

darbe

RDS MySQL replication setup tool
Python
18
star
13

tcpproxy

TCP proxy server written in Go
Go
13
star
14

resume

My resume
9
star
15

mse

BitTorrent Message Stream Encryption in Go
Go
9
star
16

go-sched

A generally useful event scheduler in Go (Golang).
Go
8
star
17

hub

Simple PubSub (Publish/Subscribe) library in Go (Golang)
Go
8
star
18

dotfiles

dotfiles management with git
Shell
7
star
19

catalyst

Caches binaries and libraries and runs a command. Used usually for decreasing release size of applications.
Go
7
star
20

kuyruk-manager

See and manage Kuyruk workers.
Python
6
star
21

AI-Writer

Swift
6
star
22

putiofs

A FUSE wrapper around put.io API v2
Python
5
star
23

remux

HTTP router that routes requests based on regex patterns.
Go
4
star
24

httpagain

Graceful restart for HTTP server (Golang)
Go
4
star
25

redialer

Generic redialer for connection-like types in Go
Go
4
star
26

container-manager

Go
3
star
27

bitfield

bitfield implementation in go
Go
3
star
28

seslisozluk-chrome

SesliSozluk.com Chrome Extension
JavaScript
3
star
29

kuyruk-go

Library for sending Kuyruk tasks from Go programs
Go
3
star
30

bcount

Cardinality counter that uses bloom filter internally.
Go
3
star
31

debe-postasi

Python
3
star
32

putio-osx-menubar

Swift
2
star
33

putio-treemap

Python
2
star
34

kuyruk-requeue

Save failed tasks to Redis and requeue them.
Python
2
star
35

math.kite

Example kite for demonstating kite framework
Go
2
star
36

puke

generate data for http speed testing
Go
2
star
37

pb

Turn long command outputs to a nice progress bar
Go
1
star
38

cenkalti.com

My home page
HTML
1
star
39

overlord

Process manager
C
1
star
40

kuyruk-sentry

Sends exceptions in Kuyruk workers to Sentry.
Python
1
star
41

cpu-guard

Shows MacOS notification if a process uses too much CPU
Swift
1
star