本文整理匯總了Python中socketIO_client.SocketIO方法的典型用法代碼示例。如果您正苦於以下問題:Python socketIO_client.SocketIO方法的具體用法?Python socketIO_client.SocketIO怎麽用?Python socketIO_client.SocketIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類socketIO_client
的用法示例。
在下文中一共展示了socketIO_client.SocketIO方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: establishConnection
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def establishConnection(self):
for i in range(self.retriesAllowed):
self.socketIO = None
try:
self.socketIO = SocketIO(self.playerComms.ipaddr, self.playerComms.port)
self.socketIO.on('pushQueue', self.pushQueue)
self.socketIO.on('pushState', self.pushState)
# self.socketIO.on(u'pushState', self.on_state_response)
# self.socketIO.on(u'pushQueue', self.on_queue_response)
# Request initial values
self.socketIO.emit(u'getQueue')
self.socketIO.emit(u'getState')
return
except Exception as ex:
del(self.socketIO)
logger.exception('Error connecting on attempt {0}'.format(i+1))
time.sleep(0.5)
pass
raise RuntimeError('Unable to connect')
示例2: run
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def run(self):
logging.debug(u"Volumio 2 musicdata service starting")
logging.debug(u"Connecting to Volumio Web Service on {0}:{1}".format(self.server, self.port))
with SocketIO(self.server, self.port) as socketIO:
logging.debug(u"Connected to Volumio Web Service")
self.socketIO = socketIO
socketIO.on(u'pushState', self.on_state_response)
socketIO.on(u'pushMultiRoomDevices', self.on_multiroomdevices_response)
socketIO.on(u'pushQueue', self.on_queue_response)
socketIO.emit(u'GetState', on_GetState_response)
# Request initial values
socketIO.emit(u'getQueue', '')
socketIO.emit(u'getState', '')
while not self.exitapp[0]:
socketIO.wait_for_callbacks(seconds=20)
socketIO.emit(u'getQueue', '')
socketIO.emit(u'getState', '')
示例3: init
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def init():
"""
Init configuration for SocketIO client.
Returns:
Event client that will be able to set listeners.
"""
from socketIO_client import SocketIO, BaseNamespace
from . import get_event_host
from gazu.client import make_auth_header
path = get_event_host()
socketIO = SocketIO(path, None, headers=make_auth_header())
main_namespace = socketIO.define(BaseNamespace, "/events")
socketIO.main_namespace = main_namespace
socketIO.on('error', connect_error)
return socketIO
示例4: startListenForMessengerServer
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def startListenForMessengerServer():
global messengerSocket
cookie = getMessengerAuthToken()
if not cookie.status_code == 200:
log.error('ERROR : Messenger username / password rejected by server')
sys.exit()
messengerSocket = SocketIO('https://%s' % messengerHost, messengerPort, LoggingNamespace, cookies={'connect.sid': cookie.cookies['connect.sid']}, transports='websocket')
log.info("Connected to messenger chat socket.io")
messengerSocket.on('connect', onHandleMessengerConnect)
messengerSocket.on('reconnect', onHandleMessengerReconnect)
messengerSocket.on('disconnect', onHandleMessengerDisconnect)
watchdog.start("MessengerServerListen", waitForMessengerServer)
return messengerSocket
示例5: watch_mempool
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def watch_mempool(crypto, callback=lambda tx: print(tx['txid']), verbose=False):
from socketIO_client import SocketIO
if verbose:
import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
logging.basicConfig()
services = get_optimal_services(crypto, 'address_balance')
for service in services:
socketio_url = service.socketio_url
if not socketio_url:
continue
try:
socketIO = SocketIO(socketio_url, verify=False,) # namespace=LoggingNamespace)
socketIO.emit('subscribe', 'inv');
socketIO.on('tx', callback)
socketIO.wait()
except KeyboardInterrupt:
return
except:
print("failed")
示例6: __init__
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def __init__(self, bot):
self.bot = bot
self.host, port_str = self.bot.config.websocket_server_url.split(':')
self.port = int(port_str)
self.sio = SocketIO(self.host, self.port)
self.sio.on(
'bot:process_request:{}'.format(self.bot.config.username),
self.on_remote_command
)
self.thread = threading.Thread(target=self.process_messages)
self.logger = logging.getLogger(type(self).__name__)
示例7: __init__
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def __init__(self, bot, url):
self.bot = bot
self.host, port_str = url.split(':')
self.port = int(port_str)
self.sio = SocketIO(self.host, self.port)
示例8: create_socket
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def create_socket(server, port):
socket = SocketIO(server, port)
socket.on('result', print_result)
socket.on('server_error', print_server_error)
return socket
示例9: create_sockets
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def create_sockets(server, port, n):
sockets = []
for i in range(0, n):
socket = SocketIO(server, port)
socket.on('result', print_result(i))
socket.on('server_error', print_server_error(i))
sockets.append(socket)
return sockets
示例10: setUp
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def setUp(self):
self.socketIO = SocketIO('localhost', 8000)
self.received_responses = 0
self.expected_responses = 0
time.sleep(1)
示例11: connect
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def connect(self, timeout=None):
timeout = timeout or 30.0
with self.lock:
if self._isConnected():
raise ValueError("'connect' called when already connected")
with self.lock:
t0 = time.time()
self.connection_status.status = ConnectionStatus.connecting
while True:
try:
self.socketIO = SocketIO(self.url, wait_for_connection=False)
break
except (TimeoutError, ConnectionError):
if time.time() - t0 > timeout:
raise
time.sleep(0.5)
self.reactorThread = threading.Thread(target=self.socketIO.wait)
if isinstance(self.socketIO._transport_instance, WebsocketTransport):
self.socketIO._transport_instance._connection.lock = threading.Lock()
self.reactorThread.daemon = True
self.namespace = self.socketIO.define(self._namespaceFactory, self.path)
self.reactorThread.start()
while self.connection_status.status == ConnectionStatus.connecting and \
(time.time() - t0 < timeout):
self.connection_cv.wait(timeout)
if self.connection_status.status == ConnectionStatus.connected:
return self
if self.connection_status.status == ConnectionStatus.connecting:
message = "Connection timed out"
else:
message = self.connection_status.message
raise pyfora.ConnectionError(message)
示例12: __init__
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def __init__(self, server_host, server_port, task_config_filename,
gpu, ignore_load):
os.environ['CUDA_VISIBLE_DEVICES'] = '%d' % gpu
self.task_config = load_json(task_config_filename)
# self.data_path = self.task_config['data_path']
print(self.task_config)
self.ignore_load = ignore_load
self.local_model = None
self.dataset = None
self.log_filename = self.task_config['log_filename']
# logger
self.logger = logging.getLogger("client")
self.fh = logging.FileHandler(os.path.join(log_dir, os.path.basename(self.log_filename)))
self.fh.setLevel(logging.INFO)
# create console handler with a higher log level
self.ch = logging.StreamHandler()
self.ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
self.formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
self.fh.setFormatter(self.formatter)
self.ch.setFormatter(self.formatter)
# add the handlers to the logger
self.logger.addHandler(self.fh)
self.logger.addHandler(self.ch)
self.logger.info(self.task_config)
self.sio = SocketIO(server_host, server_port, None, {'timeout': 36000})
self.register_handles()
print("sent wakeup")
self.sio.emit('client_wake_up')
self.sio.wait()
########## Socket Event Handler ##########
示例13: main
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def main():
global commandArgs
global robotID
global appServerSocketIO
parser = argparse.ArgumentParser(description='start robot control program')
parser.add_argument('robot_id', help='Robot ID')
parser.add_argument('--reverse-ssh-key-file', default='/home/pi/reverse_ssh_key1.pem')
parser.add_argument('--reverse-ssh-host', default='ubuntu@1.1.1.1')
commandArgs = parser.parse_args()
print commandArgs
robotID = commandArgs.robot_id
print "connecting to app server socket.io"
appServerSocketIO = SocketIO('robotstreamer.com', 8022, LoggingNamespace)
print "finished connecting to app server"
appServerSocketIO.on('connect', onHandleAppServerConnect)
appServerSocketIO.on('reconnect', onHandleAppServerReconnect)
appServerSocketIO.on('disconnect', onHandleAppServerDisconnect)
appServerSocketIO.on('reverse_ssh_8872381747239', startReverseSshProcess)
appServerSocketIO.on('end_reverse_ssh_8872381747239', endReverseSshProcess)
while True:
appServerSocketIO.wait(seconds=1)
示例14: connect
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def connect(self):
"""Initiate the channel we want to start streams from."""
self.socketIO = SocketIO(
host=self.iosocket_server,
port=80,
resource=self.iosocket_resource,
proxies=self.proxies,
headers=self.headers,
transports=["websocket"],
Namespace=AtlasNamespace,
)
self.socketIO.on(self.EVENT_NAME_ERROR, self.handle_error)
示例15: startListenForChatServer
# 需要導入模塊: import socketIO_client [as 別名]
# 或者: from socketIO_client import SocketIO [as 別名]
def startListenForChatServer():
global chatSocket
chatSocket = SocketIO(chatHostPort['host'], chatHostPort['port'], LoggingNamespace, transports='websocket')
log.info("Connected to chat socket.io")
chatSocket.on('chat_message_with_name', onHandleChatMessage)
chatSocket.on('connect', onHandleChatConnect)
chatSocket.on('reconnect', onHandleChatReconnect)
chatSocket.on('disconnect', onHandleChatDisconnect)
watchdog.start("ChatServerListen", waitForChatServer)
return chatSocket