https://github.com/zoujiaqing/qrpc
QUIC protocol based simple RPC framework
https://github.com/zoujiaqing/qrpc
quic quic-client quic-go quic-server rpc udp
Last synced: 4 months ago
JSON representation
QUIC protocol based simple RPC framework
- Host: GitHub
- URL: https://github.com/zoujiaqing/qrpc
- Owner: zoujiaqing
- License: mit
- Created: 2024-05-14T06:19:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-22T11:27:04.000Z (over 1 year ago)
- Last Synced: 2024-05-22T15:33:10.742Z (over 1 year ago)
- Topics: quic, quic-client, quic-go, quic-server, rpc, udp
- Language: Go
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QRPC
A simple rpc framework that works over [QUIC](https://en.wikipedia.org/wiki/QUIC) written in Golang.
## Client sample code
```go
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++
}
}
```
## Server sample code
```go
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)
}
```
## Run examples
examples include grpc client and server sample code
### Load dependency
```bash
go mod dity
```
### Run server for example
```bash
go run ./examples/server
```
### Run client for example
```bash
go run ./examples/client
```