| 1 |
# Unix Domain Socket Example in gRPC Python |
| 2 |
|
| 3 |
## Check Our Guide First |
| 4 |
|
| 5 |
For knowing the basics of gRPC Python and the context around the helloworld example, please checkout our gRPC Python [Quick Start guide](https://grpc.io/docs/languages/python/quickstart). |
| 6 |
|
| 7 |
## Overview |
| 8 |
|
| 9 |
This example demonstrate how gRPC Python can utilize the gRPC Name Resolution mechanism to specify UDS address for clients and servers. The gRPC Name Resolution mechanism is documented at https://github.com/grpc/grpc/blob/master/doc/naming.md. |
| 10 |
|
| 11 |
Specifically, this example will bind the server to the following UDS addresses, and use clients to connect to them: |
| 12 |
|
| 13 |
* `unix:path`: setting the unix domain socket path relatively or absolutely |
| 14 |
* `unix://absolute_path`: setting the absolute path of the unix domain socket |
| 15 |
|
| 16 |
## Prerequisite |
| 17 |
|
| 18 |
The Python interpreter should have `grpcio` and `protobuf` installed. |
| 19 |
|
| 20 |
## Running The Example |
| 21 |
|
| 22 |
Starting the server: |
| 23 |
|
| 24 |
``` |
| 25 |
$ python3 greeter_server.py |
| 26 |
INFO:root:Server listening on: unix:helloworld.sock |
| 27 |
INFO:root:Server listening on: unix:///tmp/helloworld.sock |
| 28 |
... |
| 29 |
``` |
| 30 |
|
| 31 |
``` |
| 32 |
$ python3 async_greeter_server.py |
| 33 |
INFO:root:Server listening on: unix:helloworld.sock |
| 34 |
INFO:root:Server listening on: unix:///tmp/helloworld.sock |
| 35 |
... |
| 36 |
``` |
| 37 |
|
| 38 |
Connecting with a client: |
| 39 |
|
| 40 |
``` |
| 41 |
$ python3 greeter_client.py |
| 42 |
INFO:root:Received: Hello to unix:helloworld.sock! |
| 43 |
INFO:root:Received: Hello to unix:///tmp/helloworld.sock! |
| 44 |
``` |
| 45 |
|
| 46 |
``` |
| 47 |
$ python3 async_greeter_client.py |
| 48 |
INFO:root:Received: Hello to unix:helloworld.sock! |
| 49 |
INFO:root:Received: Hello to unix:///tmp/helloworld.sock! |
| 50 |
``` |