def run(self):
     log.info('Running server on port %d' % self.port)
     rpcprotocol = RPCProtocol()
     self.tcpserver = TCPServer(self.handler,rpcprotocol)
     self.tcpserver.bind(self.port, self.host)
     self.tcpserver.start(0)
     ioloop.IOLoop.instance().start()
示例#2
0
def get_request():
    input = rpc_pb2.Request()
    service = UserServiceImpl()
    input.service_name = service.GetDescriptor().full_name
    input.method_name = 'UserLogin'
    data = user_pb2.UserLoginRequest()
    data.user_name = '*****@*****.**'
    data.user_pass = '******'
    input.request_proto = data.SerializeToString()
    request = input.SerializeToString()
    protocol = RPCProtocol()
    return protocol.build_request(request)
def get_request():
    input = rpc_pb2.Request()
    service = ServerStatus()
    input.service_name = service.GetDescriptor().full_name
    input.method_name = 'RPCStatus'
    data = status_pb2.TCPRequest()
    data.client_ip = 'Zach'
    data.user_name = 'Zach'
    data.user_pass = '******'
    input.request_proto = data.SerializeToString()
    request = input.SerializeToString()
    #print binascii.hexlify(request)
    protocol = RPCProtocol()
    return protocol.build_request(request)
示例#4
0
def run():
    request = get_request()
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(('localhost', 8080))
    sock.send(request)
    recv = sock.recv(6)
    protocol = RPCProtocol()
    len = protocol.request_len(recv)
    print len
    ret = sock.recv(len)
    response = rpc_pb2.Response()
    response.ParseFromString(ret)
    service_res = user_pb2.UserLoginResponse()
    service_res.ParseFromString(response.response_proto)
    print service_res.login
    sock.close()