示例#1
0
    def setup(self):
        self.publ_info = self.sio_queue[0].get()
        self.cfg = self.sio_queue[0].get()

        assert isinstance(self.publ_info, SlavePublInfo)
        self.publ_info.cfg = self.cfg
        self.pvte_info.cfg = self.cfg

        self.setup_logger()

        self.publ_info.update_load()

        # S1.1: Setup namespace.
        from waldorf.namespace.slave import Namespace
        self.logger.debug(
            'Connect to {}:{} with uid {}'.format(
                self.cfg.master_ip, self.cfg.waldorf_port,
                self.publ_info.uid))
        if self.cfg.debug >= 2:
            sio = Client(logger=self.logger)
        else:
            sio = Client()
        self.pvte_info.sio = sio
        ns = Namespace('/slave')
        ns.setup(self)
        self.pvte_info.ns = ns
        sio.register_namespace(ns)
        sio.connect('http://{}:{}'.format(
            self.cfg.master_ip, self.cfg.waldorf_port))
示例#2
0
    def setup(self):
        # S1: Setup socketio client.
        self.publ_info = self.sio_queue[0].get()
        self.cfg = self.sio_queue[0].get()

        assert isinstance(self.publ_info, ClientPublInfo)
        self.publ_info.cfg = self.cfg
        self.pvte_info.cfg = self.cfg
        self.ignore_events = ['submit']

        # S1.1: Setup logger.
        self.setup_logger()

        # S1.2: Connect to Waldorf master.
        from waldorf.namespace.client import Namespace
        self.logger.debug(
            'Connect to {}:{} with uid {}'.format(
                self.cfg.master_ip, self.cfg.waldorf_port,
                self.publ_info.uid))
        if self.cfg.debug >= 2:
            sio = Client(logger=self.logger)
        else:
            sio = Client()
        self.pvte_info.sio = sio
        ns = Namespace('/client')
        ns.setup(self)
        self.pvte_info.ns = ns
        sio.register_namespace(ns)
        sio.connect('http://{}:{}'.format(
            self.cfg.master_ip, self.cfg.waldorf_port))

        self.result_q = [queue.Queue(), self.submit_queue[0]]
        CeleryResultThread(self).start()
示例#3
0
    def on_disconnect(self):
        print('on_disconnect')

    def get_current_price(self):
        tickers = pyupbit.get_tickers(fiat="KRW")

        while True:
            markets = pyupbit.get_current_price(tickers)
            client.emit(
                "send_price",
                dict(tickers=tickers, markets=markets, size=len(markets)))
            time.sleep(1)


client = UpbitClientNamespace('/upbit')

sio = Client()
sio.register_namespace(client)
sio.connect('http://localhost:3000', namespaces=['/upbit'])

sio.start_background_task(client.get_current_price)

print(sio.connected)
print(sio.connection_namespaces)

try:
    sio.wait()
except KeyboardInterrupt as e:
    if sio.connected:
        sio.disconnect()
示例#4
0
    define("ip",
           default='127.0.0.1',
           help="Server IP to connect to, default 127.0.0.1")
    define("verbose", default=False, help="verbose")
    options.parse_command_line(
        final=False
    )  # final False is required or it activates the client logger.

    if options.ip != '127.0.0.1':
        URL = "ws://{}:{}/chat/".format(options.ip, DEFAULT_PORT)
        print("Using {}".format(URL))

    # See options https://python-socketio.readthedocs.io/en/latest/api.html
    sio = Client(logger=False)
    sio.register_namespace(ChatNamespace('/chat'))
    sio.connect('http://{}:{}'.format(options.ip, DEFAULT_PORT),
                namespaces=['/chat'])

    sleep(1)  # not needed
    # We have to id ourselve first of all
    sio.emit('hello',
             data={
                 "version": 2,
                 "ip": "127.0.0.1",
                 "port": DEFAULT_PORT
             },
             namespace="/chat")

    # ask the peer active list
    sio.emit('get_peers', data={}, namespace="/chat")
示例#5
0
        sleep(10)
        sio.emit('nonce', data="fakenonce", namespace="/pool")


if __name__ == "__main__":

    define("ip",
           default='127.0.0.1',
           help="Pool IP to connect to, default 127.0.0.1")
    define("address", help="Yadacoin address to mine to")
    define("verbose", default=False, help="verbose")
    options.parse_command_line(
        final=False
    )  # final False is required or it activates the client logger.

    if options.ip != '127.0.0.1':
        URL = "http://{}:{}".format(options.ip, DEFAULT_PORT)
        print("Using {}".format(URL))

    # See options https://python-socketio.readthedocs.io/en/latest/api.html
    sio = Client(logger=False, reconnection=False)
    sio.register_namespace(PoolNamespace('/pool'))
    sio.connected = True
    sio.connect('http://{}:{}'.format(options.ip, DEFAULT_PORT),
                namespaces=['/pool'])
    sleep(10)
    # We have to id ourselve first of all
    mine()
    # sio.wait()
    sio.disconnect()