def __init__(self): """ 初始化 """ self._client = Client() self._lock = Lock() self._enter_num = 0
def __exit__(self, exc_type, exc_val, exc_tb): """ 退出时自动断开,并重置客户端 """ with self._lock: self._enter_num -= 1 if self._enter_num == 0: self._client.close() self._client = Client()
def __init__(self, name): location = _SERVICES_LOC.get(name) if location is not None: self.client = Client() self.client.connect(location) else: # direct import self.client = None self._mod = imp.load_module(name, *imp.find_module(name))
def __enter__(self): """ 当进入的线程为 0 时,重置客户端并自动连接 """ with self._lock: if self._enter_num == 0: self._client = Client() self._client.connect(self.endpoint) self._enter_num += 1 return self
def __init__(self, client_ip): # Setup pusher service self.client = Client() self.client.connect(client_ip) # print(self.pusher.load_data("TEST")) # Connect to message hub self._hub = Hub() self._hub.subscribe(Message.LoadData, self.client.load_data, self)
def main(): dbServer = Client() dbServer.connect('tcp://127.0.0.1:8000') app = Sanic() @app.route('/stats/distrib') async def distrib(request): potatoes = dbServer.get_all_potatoes() pie_chart = pygal.Pie() for potato in potatoes: pie_chart.add(potato['type'], int(potato['count'])) return HTTPResponse( body_bytes=pie_chart.render(), status=200, headers=None, content_type="image/svg+xml") app.run(host="0.0.0.0", port=9000)
class RPCClient(object): def __init__(self, app_id, app_secret, endpoint): self.app_id = app_id self.app_secret = app_secret self.endpoint = endpoint def call_old(self, access_token='', method='', path=(), params={}, async=False): self.client = Client(heartbeat=60, timeout=60) self.client.connect(self.endpoint) res = self.client.call(self.app_id, self.app_secret, access_token, method, path, params, async=async)
def index(): mqtt_client = Client() mqtt_client.connect('tcp://127.0.0.1:2048') if not request.args: return "未传token" else: token = request.args.get('token').encode() str_token = token.decode('utf-8') action = request.get_json() print(action) sql_data = json.dumps(SearrchORM.select_user(str_token)) print(sql_data) # 鉴权 certify_token(key=sql_data, token=token) # 调用下发指令 print(mqtt_client.dispatch_action('lua/test/data/456', action)) # response return template_jsonify({})
def __init__(self): """ 初始化 """ self._client = Client()
# -*- coding: utf-8 -*- from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity from yowsup.layers.protocol_acks.protocolentities import OutgoingAckProtocolEntity from json import dumps from zerorpc import Client c = Client() c.connect('tcp://127.0.0.1:4242') class EchoLayer(YowInterfaceLayer): @ProtocolEntityCallback('message') def onMessage(self, messageProtocolEntity): if True: self.toLower( OutgoingReceiptProtocolEntity( messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), 'read', messageProtocolEntity.getParticipant())) self.toLower( TextMessageProtocolEntity(c.input( self.out(messageProtocolEntity)), to=messageProtocolEntity.getFrom())) @ProtocolEntityCallback('receipt') def onReceipt(self, entity): self.toLower(
def __init__(self, location): self.client = Client() self.client.connect(location)
def __init__(self, client_ip): # Setup pusher service self.client = Client() self.client.connect(client_ip)