Other Subscription Events
Connection Successful
PushClient.connect_callback
Description
Invoked after a connection is established successfully.
Parameters
frame
Return
None
Example
import time
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):
"""Handle a successful connection."""
print('connected')
push_client.connect_callback = connect_callback
Disconnection
PushClient.disconnect_callback
Description
Invoked when the connection closes.
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 Exception:
print('connect failed, retry')
time.sleep(t)
else:
print('reconnect success')
break
# Initialize push_client as shown above
push_client.disconnect_callback = disconnect_callback
Connection Error
PushClient.error_callback
Description
Invoked when a connection error occurs.
Parameters
Parameter for receiving error information
Return
None
Example
def error_callback(frame):
"""Handle a connection error.
:param frame: Error information.
"""
print(frame)
# Initialize push_client as shown above
push_client.error_callback = error_callbackConnection Kicked Out
PushClient.kickout_callback(frame)
Description
Invoked when a newer connection replaces the current connection for the same identity.
Parameters
Parameter for receiving kicked-out error information
Return
None
Example
import logging
logger = logging.getLogger(__name__)
def kickout_callback(frame):
logger.error(f'kickout callback: {frame}')
push_client.kickout_callback = kickout_callback
Updated about 2 months ago
Did this page help you?
