github.com/laof/lite-speed-test@v0.0.0-20230930011949-1f39b7037845/api/rpc/liteclientpy/client.py (about) 1 import grpc 2 import lite_pb2_grpc as pb2_grpc 3 import lite_pb2 as pb2 4 5 6 class LiteClient(object): 7 """ 8 Client for gRPC functionality 9 """ 10 11 def __init__(self): 12 self.host = '127.0.0.1' 13 self.server_port = 10999 14 15 # instantiate a channel 16 self.channel = grpc.insecure_channel( 17 '{}:{}'.format(self.host, self.server_port)) 18 19 # bind the client and the server 20 self.stub = pb2_grpc.TestProxyStub(self.channel) 21 22 def start_test(self): 23 """ 24 Client function to call the rpc for StartTest 25 """ 26 message = pb2.TestRequest( 27 GroupName="Default", 28 SpeedTestMode=pb2.SpeedTestMode.all, 29 PingMethod=pb2.PingMethod.googleping, 30 SortMethod=pb2.SortMethod.rspeed, 31 Concurrency=2, 32 TestMode=2, 33 Subscription="https://raw.githubusercontent.com/freefq/free/master/v2", 34 Language="en", 35 FontSize=24, 36 Theme="rainbow", 37 Timeout=10, 38 OutputMode=0 39 ) 40 print(f'{message}') 41 for response in self.stub.StartTest(message): 42 print(f'{response}') 43 44 45 if __name__ == '__main__': 46 client = LiteClient() 47 client.start_test() 48