A simple rpc framework that works over QUIC written in Golang.
package main
import (
"log"
"time"
"github.com/zoujiaqing/qrpc"
)
func main() {
client := qrpc.NewClient("localhost", 4444)
if err := client.Connect(); err != nil {
return err
}
client.OnRequest(func(data []byte) []byte {
return append([]byte("From Client Respond "), data...)
})
var i uint64 = 1
for {
data, err := client.Request([]byte("Hello"))
if err != nil {
log.Printf("Request error: %v", err)
break
}
log.Printf("Respond(%d): %s", i, string(data))
time.Sleep(1 * time.Second)
i++
}
}
package main
import (
"context"
"github.com/zoujiaqing/qrpc"
)
func main() {
server, err := qrpc.NewServer(4444)
if err != nil {
return err
}
defer func() { _ = server.Close() }()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
server.Accept(ctx)
}
examples include grpc client and server sample code
go mod dity
go run ./examples/server
go run ./examples/client