Beispiel #1
0
    def __init__(self, init_mode, host, port=MPM_RPC_PORT, token=None):
        assert isinstance(init_mode, InitMode)
        print("[MPMRPC] Attempting to connect to {host}:{port}...".format(
            host=host, port=port))
        self._remote_methods = []
        if init_mode == InitMode.Hijack:
            assert token
            self._token = token
        if init_mode == InitMode.Claim:
            self._claimer = MPMClaimer(host, port)
            self._claimer.claim()
            self._token = self._claimer.token

        try:
            self._client = RPCClient(host,
                                     port,
                                     pack_params={'use_bin_type': True})
            print("[MPMRPC] Connection successful.")
        except Exception as ex:
            print("[MPMRPC] Connection refused: {}".format(ex))
            raise RuntimeError("RPC connection refused.")
        print("[MPMRPC] Getting methods...")
        methods = self._client.call('list_methods')
        for method in methods:
            self._add_command(*method)
        print("[MPMRPC] Added {} methods.".format(len(methods)))
Beispiel #2
0
 def connect(self, host, port):
     """
     Launch a connection.
     """
     print("Attempting to connect to {host}:{port}...".format(host=host,
                                                              port=port))
     try:
         self.client = RPCClient(host,
                                 port,
                                 pack_params={'use_bin_type': True})
         print("Connection successful.")
     except Exception as ex:
         print("Connection refused")
         print("Error: {}".format(ex))
         return False
     self._host = host
     self._port = port
     print("Getting methods...")
     methods = self.client.call('list_methods')
     for method in methods:
         self._add_command(*method)
     print("Added {} methods.".format(len(methods)))
     print("Quering device info...")
     self._device_info = self.client.call('get_device_info')
     return True
Beispiel #3
0
 def __init__(self, host="127.0.0.1", port=9033, model="en", embeddings_path=None, verbose=False, attributes=None):
     super(Client, self).__init__(model, embeddings_path)
     self.host = host
     self.port = port
     self.rpc = RPCClient(host, port)
     self.verbose = verbose
     self.attributes = attributes
     self.cache = LRUCache(maxsize=3000000)
Beispiel #4
0
def call_register(uuid):
    print("Registering peer with uuid: {}".format(uuid))

    client = RPCClient(b'localhost', 18080)
    res = client.call(b'register', uuid)
    client.close()

    return res
Beispiel #5
0
def call():
    from mprpc import RPCClient

    client = RPCClient('127.0.0.1', 6000)

    start = time.time()
    [client.call('sum', 1, 2) for _ in xrange(NUM_CALLS)]

    print 'call: %d qps' % (NUM_CALLS / (time.time() - start))
Beispiel #6
0
def call():
    from mprpc import RPCClient

    client = RPCClient('ipc://x.sock')

    start = time.time()
    [client.call('sum', 1, 2) for _ in xrange(NUM_CALLS)]

    print 'call: %d qps' % (NUM_CALLS / (time.time() - start))
Beispiel #7
0
class CVPChatClient:
    Client = RPCClient('127.0.0.1', 20181)

    while (True):
        Client.call('SendMessage', "Hello")
        Client.call('SendMessage', "JAM")
        Client.call('SendMessage', "x3")

        print(Client.call('GetRecentMessage'))
        time.sleep(1)
Beispiel #8
0
def call_get_schedule(uuid, num, method="smart"):
    print("Getting schedule for uuid: {}".format(uuid))

    data = {'uuid': uuid, 'num': num, 'method': method}

    client = RPCClient(b'localhost', 18080)
    result = client.call(b'get_schedule', data)
    client.close()

    return result
Beispiel #9
0
 def __init__(self,
              host="127.0.0.1",
              port=9033,
              model="en",
              embeddings_path=None,
              verbose=False):
     super(Client, self).__init__(model, embeddings_path)
     self.host = host
     self.port = port
     self.rpc = RPCClient(host, port)
     self.verbose = verbose
Beispiel #10
0
 def __init__(self, host, port):
     self.token = None
     self._cmd_q = multiprocessing.Queue()
     self._token_q = multiprocessing.Queue()
     client = RPCClient(host, port, pack_params={'use_bin_type': True})
     self._claim_loop = multiprocessing.Process(target=_claim_loop,
                                                name="Claimer Loop",
                                                args=(client, self._cmd_q,
                                                      self._token_q))
     self._claim_loop.daemon = True
     self._claim_loop.start()
Beispiel #11
0
def rpc(address, port, command, *args):
    if not port:
        port = mpm.types.MPM_RPC_PORT
    client = RPCClient(address, port)
    if args:
        args = [
            eval(arg.lstrip("=")) if arg.startswith("=") else arg
            for arg in args
        ]
        result = client.call(command, *args)
    else:
        result = client.call(command)
    return result
Beispiel #12
0
 def connect(self):
     try:
         if not self.OK:
             self._link_ = RPCClient(self.host, int(self.port), timeout=20)
             if self._link_.is_connected():
                 self.OK = self.__create_hooks()
             else:
                 self.OK = False
     except:
         self.OK = False
         if self.showerr:
             P_Log("[FR]ERROR [FW] No Connect to {}".format(uri))
     finally:
         return self.OK
Beispiel #13
0
def call():
    from mprpc import RPCClient

    client = RPCClient('127.0.0.1', 7777)

    t = np.zeros(NUM_CALLS)

    for _ in range(NUM_CALLS):
        t1 = time.time()
        client.call('sum', 1, 2)
        t2 = time.time()
        t[_] = t2 - t1

    print('stdev: {}'.format(t.std()))
    print('mean: {}'.format(t.mean()))
    print('call: {} qps'.format(1 / t.mean()))
Beispiel #14
0
 def claim_loop(self, host, port, disc_callback):
     """
     Run a claim loop
     """
     client = RPCClient(host, port, pack_params={'use_bin_type': True})
     self.token = client.call('claim', 'MPM Shell')
     try:
         while not self._exit_loop:
             client.call('reclaim', self.token)
             time.sleep(1)
         client.call('unclaim', self.token)
     except RPCError as ex:
         print("Unexpected RPC error in claimer loop!")
         print(str(ex))
     disc_callback()
     self.token = None
Beispiel #15
0
    def __init__(self, uri, show=False):
        self.showerr = show
        try:
            self.host, self.port = uri.split(":")
        except:
            self.host = "0.0.0.0"
            self.port = 0

        self.OK = False
        self.__linked = False
        try:
            self._link_ = RPCClient(self.host, int(self.port), timeout=10)
            self.__linked = True
        except:
            self.__linked = False
            if show:
                P_Log("[FR]ERROR [FW] No Link to {}".format(uri))
    def __exec_mprpc__(self, args):
        from mprpc import RPCClient, RPCPoolClient

        method = args[0]
        args = args[1]
        assert method in ["get", "set"]
        try:
            client = RPCClient(self.server, self.mprpc_port)
            result = client.call(method, args)
            client.close()
            return result
        except Exception as e:
            print(e)
            try:
                client.close()
            except:
                pass
Beispiel #17
0
    def test_server(self, server):
        class Sum:
            def sum(self, x, y):
                return x + y

        server.load(Sum)
        self.g = gevent.spawn(server.run)
        sleep(0.1)

        registry = server.registry
        res = registry.discovery(server.name)
        key = registry._node_key(server.name, url.get_param("node"))

        host, port = res[key].split(":")

        client = RPCClient(str(host), int(port))

        assert client.call("sum", {}, 1, 2) == 3
Beispiel #18
0
def _claim_loop(host, port, cmd_q, token_q):
    """
    Process that runs a claim loop.

    This function should be run in its own thread. Communication to the outside
    thread happens with two queues: A command queue, and a token queue. The
    command queue is used to pass in one of these commands: claim, unclaim, or
    exit.
    The token queue is used to read back the current token.
    """
    command = None
    token = None
    exit_loop = False
    client = RPCClient(host, port, pack_params={'use_bin_type': True})
    try:
        while not exit_loop:
            if token and not command:
                client.call('reclaim', token)
            elif command == 'claim':
                if not token:
                    token = client.call('claim', 'UHD')
                else:
                    print("Already have claim")
                token_q.put(token)
            elif command == 'unclaim':
                if token:
                    client.call('unclaim', token)
                token = None
                token_q.put(None)
            elif command == 'exit':
                if token:
                    client.call('unclaim', token)
                token = None
                token_q.put(None)
                exit_loop = True
            time.sleep(1)
            command = None
            if not cmd_q.empty():
                command = cmd_q.get(False)
    except RPCError as ex:
        print("Unexpected RPC error in claimer loop!")
        print(str(ex))
Beispiel #19
0
 def claim_loop(self, host, port, cmd_q, token_q):
     """
     Run a claim loop
     """
     from mprpc import RPCClient
     from mprpc.exceptions import RPCError
     command = None
     token = None
     exit_loop = False
     client = RPCClient(host, port, pack_params={'use_bin_type': True})
     try:
         while not exit_loop:
             if token and not command:
                 client.call('reclaim', token)
             elif command == 'claim':
                 if not token:
                     token = client.call('claim', 'MPM Shell')
                 else:
                     print("Already have claim")
                 token_q.put(token)
             elif command == 'unclaim':
                 if token:
                     client.call('unclaim', token)
                 token = None
                 token_q.put(None)
             elif command == 'exit':
                 if token:
                     client.call('unclaim', token)
                 token = None
                 token_q.put(None)
                 exit_loop = True
             time.sleep(1)
             command = None
             if not cmd_q.empty():
                 command = cmd_q.get(False)
     except RPCError as ex:
         print("Unexpected RPC error in claimer loop!")
         print(str(ex))
Beispiel #20
0
 def connect():
     if Call.client is None:
         Call.client = RPCClient("127.0.0.1", port=6000, timeout=3000)
Beispiel #21
0
# -*- coding: utf-8 -*-
"""如果想用gevent, 可以用gevent patch all
"""
from mprpc import RPCClient

client = RPCClient('tcp://127.0.0.1:6000', reconnect_delay=5)
print client.call('sum', 1, 2)
Beispiel #22
0
from mprpc import RPCClient

client = RPCClient('127.0.0.1', 6000)
print client.call('add', 1000, 1000)
Beispiel #23
0
 def connect(self):
     self.urlserver = RPCClient(config["URLSERVER"].split(":")[0],
                                int(config["URLSERVER"].split(":")[1]))
Beispiel #24
0
# -*- coding: utf-8 -*-

from mprpc import RPCClient

client = RPCClient(unix_socket_path='/tmp/rpc.sock')
print client.call('sum', 1, 2)
Beispiel #25
0
def call():
    client = RPCClient('ipc://x.sock', reconnect_delay=5)

    print client.call('sum', 1, 2)
def callraspi():
    client = RPCClient("133.27.171.245", 6000)
    print(client.call('unlock_key'))
Beispiel #27
0
#import pyjsonrpc

from mprpc import RPCClient
'''
from paramiko import SSHClient
from scp import SCPClient

ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect('192.168.1.16', username='******', password='******', look_for_keys=False)

with SCPClient(ssh.get_transport()) as scp:
    scp.put("/home/pi/Desktop/pyUI/profiles/aaa/top/aaa.jpg", "/home/pi/Desktop/aaa.jpg")
'''
client = RPCClient('127.0.0.1', 8080)
print(client.call('add', 1, 2))
print(client.call('updateProfile', ""))
print(client.call('profilepath', '/home/pi/Desktop/pyUI/profiles', 'aaa'))
print(client.call('ResultTest', 5))
#client.call('Init')
client.call('TakePicture', 0, False)
client.call('TakePicture', 1)
client.call('TakePicture', 2)
client.call('CreateSamplePoint', 0, 150, 200)
#client.call('Uninit')
client.call('CloseServer')
'''
http_client = pyjsonrpc.HttpClient(
    url = "http://localhost:8080/jsonrpc"
    #username = "******",
Beispiel #28
0
def call():
    client = RPCClient('127.0.0.1', 6000)

    print client.call('sum', 1, 2)
Beispiel #29
0
import numpy as np
from mprpc import RPCClient

client = RPCClient('127.0.0.1', 9033)

with client_pool.connection() as client:
    vec = client.call('embedding', ['hey', 'there', 'how', 'are', 'you'])
    print(np.shape(vec))
Beispiel #30
0
    def __init__(self, symbol=SYMBOL, resolution=60, port=PROXY_PORT):
        super().__init__(symbol, resolution)

        self.client = RPCClient('127.0.0.1', port)
        self.data = self.client.call('ohlcv', TICKERID, self.resolution, 256)