Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pahanini/go-grpc-bidirectional-streaming-example
gRPC bidirectional streaming example written in golang
https://github.com/pahanini/go-grpc-bidirectional-streaming-example
bidirectional context demo example golang grpc streaming tutorial
Last synced: 4 days ago
JSON representation
gRPC bidirectional streaming example written in golang
- Host: GitHub
- URL: https://github.com/pahanini/go-grpc-bidirectional-streaming-example
- Owner: pahanini
- License: mit
- Created: 2017-11-29T06:28:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-11T17:39:24.000Z (6 months ago)
- Last Synced: 2024-12-15T03:05:44.810Z (11 days ago)
- Topics: bidirectional, context, demo, example, golang, grpc, streaming, tutorial
- Language: Go
- Size: 59.6 KB
- Stars: 117
- Watchers: 2
- Forks: 34
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Golang gRPC bidirectional streaming example
- client sends random numbers to server
- server receives number and sends it back if the number greater than all previous numbers
- both client and server handle context errors (try to close client during send)## Requirements
- go 1.17.1
- protobuf installed
- go support for protobuf installed## Installation
### MacOS
```bash
brew install go
brew install protobuf
go install google.golang.org/grpc/cmd/[email protected]
```Make sure ```protoc-gen-go``` added in PATH
To add it to PATH you can use bash profile for example.
Edit ```vim ~/.bash_profile```, add: ```export PATH="$PATH:$(go env GOPATH)/bin"```, run ```source ~/.bash_profile```
to apply changes.### Linux
TBD
## Complie
```bash
make all
```It should create two binaries `server` and `client`
## Use
Start server `./server` and in other terminal start `./client`
Client output example:
```bash
./client
2017/12/01 14:16:54 0 sent
2017/12/01 14:16:54 1 sent
2017/12/01 14:16:54 new max 1 received
2017/12/01 14:16:55 2 sent
2017/12/01 14:16:55 new max 2 received
2017/12/01 14:16:55 0 sent
2017/12/01 14:16:55 0 sent
2017/12/01 14:16:55 4 sent
2017/12/01 14:16:55 new max 4 received
2017/12/01 14:16:55 0 sent
2017/12/01 14:16:56 6 sent
2017/12/01 14:16:56 new max 6 received
2017/12/01 14:16:56 3 sent
2017/12/01 14:16:56 2 sent
2017/12/01 14:16:56 finished with max=6
```Server output:
```bash
./server
2017/12/01 14:16:54 start new server
2017/12/01 14:16:54 send new max=1
2017/12/01 14:16:55 send new max=2
2017/12/01 14:16:55 send new max=4
2017/12/01 14:16:56 send new max=6
2017/12/01 14:16:56 exit
````