Other Subscription Events
Connection Successful
PushClient.connect_callback
Description
Callback for successful connection
Parameters
frame
Return
None
Example
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
# Initialize PushClient
protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))
def connect_callback(frame):
"""Callback for successful connection establishment"""
print('connected')
push_client.connect_callback = connect_callback
Disconnection
PushClient.disconnect_callback
Description
Callback for connection disconnection
Parameters
None
Return
None
Example
def disconnect_callback():
"""Reconnect after disconnection"""
for t in range(1, 200):
try:
print('disconnected, reconnecting...')
push_client.connect(client_config.tiger_id, client_config.private_key)
except:
print('connect failed, retry')
time.sleep(t)
else:
print('reconnect success')
break
# The steps to initialize push_client are omitted, same as above
push_client.disconnect_callback = disconnect_callback
Connection Error
PushClient.error_callback
Description
Callback for connection errors
Parameters
Parameter for receiving error information
Return
None
Example
def error_callback(frame):
"""Error callback
:param content: Error information
"""
print(frame)
# The steps to initialize push_client are omitted, same as above
push_client.error_callback = error_callbackConnection Kicked Out
PushClient.kickout_callback(frame)
Description
Callback for connection being kicked out. When multiple devices are connected, the old device will receive this callback when it is kicked out by a new device.
Parameters
Parameter for receiving kicked-out error information
Return
None
Example
def kickout_callback(frame):
logger.error(f'kickout callback: {frame}')
push_client.kickout_callback = kickout_callback
Updated 13 days ago
