Пример #1
0
async def main() -> None:
    async with Channel('127.0.0.1', 50051) as channel:
        listen(channel, SendRequest, on_send_request)

        stub = GreeterStub(channel)
        response = await stub.SayHello(HelloRequest(name='World'))
        print(response.message)
Пример #2
0
import struct
import asyncio
import tempfile
import subprocess

import click

from grpclib.utils import graceful_exit
from grpclib.server import Server
from grpclib.encoding.proto import ProtoCodec

from helloworld.server import Greeter
from helloworld.helloworld_pb2 import HelloRequest, HelloReply

REQUEST = HelloRequest(name='Dr. Strange')


def grpc_encode(message, message_type, codec=ProtoCodec()):
    message_bin = codec.encode(message, message_type)
    header = struct.pack('?', False) + struct.pack('>I', len(message_bin))
    return header + message_bin


@click.group()
def cli():
    pass


@cli.group()
def serve():
Пример #3
0
def call():
    with grpc.insecure_channel(target="127.0.0.1:5051") as channel:
        stub = GreeterStub(channel)
        resp = stub.SayHello(HelloRequest(name='comyn'))
        return resp.message