24 lines
621 B
Python
24 lines
621 B
Python
"""Greeter server."""
|
|
from purerpc import Server
|
|
|
|
from greeter_grpc import GreeterServicer
|
|
from greeter_pb2 import HelloReply, HelloRequest
|
|
|
|
|
|
class Greeter(GreeterServicer):
|
|
async def SayHello(self, message):
|
|
return HelloReply(message=f"Hello, {message.name}")
|
|
|
|
async def SayHelloToMany(self, input_messages):
|
|
async for message in input_messages:
|
|
yield HelloReply(message=f"Hello, {message.name}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
server = Server(50055)
|
|
server.add_service(Greeter().service)
|
|
try:
|
|
server.serve(backend="trio")
|
|
except KeyboardInterrupt:
|
|
pass
|