https://github.com/humbertodias/unity-grpc-min
Minimal GRPC unary server/client using Unity as Client.
https://github.com/humbertodias/unity-grpc-min
grpc python unity
Last synced: about 2 months ago
JSON representation
Minimal GRPC unary server/client using Unity as Client.
- Host: GitHub
- URL: https://github.com/humbertodias/unity-grpc-min
- Owner: humbertodias
- Created: 2018-11-22T13:11:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-23T11:32:47.000Z (over 6 years ago)
- Last Synced: 2025-12-23T08:59:48.622Z (6 months ago)
- Topics: grpc, python, unity
- Language: Makefile
- Homepage:
- Size: 250 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Unity-GRPC-min
Minimal GRPC unary server/client using Unity as Client.
# Deps
* Make
* Unity 2018.2+
* Python 2
# Arch

## Proto
```proto
// For Unity
option csharp_namespace = "Pj.Grpc.Sample";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
```
## Server
```python
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
```
or
```go
func (*server) SayHello(ctx context.Context, req *pb.HelloRequest) (*pb.HelloReply, error) {
fmt.Printf("Greet function was involked with %v\n", req)
result := "Hello " + req.GetName()
res := &pb.HelloReply{
Message: result,
}
return res, nil
}
```
## Client
```csharp
public void Say()
{
Channel channel = new Channel(ip + ":" + port, ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
string name = Application.platform.ToString();
var reply = client.SayHello(new HelloRequest { Name = name });
Debug.Log("reply: " + reply.Message);
text.text = "reply: " + reply.Message;
channel.ShutdownAsync().Wait();
}
```
# Build
# Dep
make dep
sudo command will ask for your local password to install protoc
## Server
make build-server
Will generate the proto stub layer in server/python/helloworld*.py
## Client
make build-client
Will generate the proto bridge classes in client/csharp-unity/Assets/GRPC/*
# Run
## Server
make run-server-python
or with go
make go-install
make run-server-go
Listening at 50051 port.
## Client
On Unity open the project client/csharp-unity and hit Play
The result must be

# Ref
* [packages.grpc.io](https://packages.grpc.io)
* [gRPC with Unity](https://shamaton.orz.hm/blog/archives/553)