Other Events
Less than 1 minute
Connection Established
PushClient.connect_callback
Description
Callback for successfully establishing a connection
Arguments
frame
Response
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 sucessfully establish a connection"""
print('connected')
push_client.connect_callback = connect_callback
Disconnect
PushClient.disconnect_callback
Description
Callback for disconnection
Arguments
None
Response
None
Example
def disconnect_callback():
"""Attempt to re-connect"""
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
push_client.disconnect_callback = disconnect_callback
Connection Error
PushClient.error_callback
Description
Call back for error
Arguments
A variable to save the error message
Response
None
Example
def error_callback(content):
"""Error Callback
:param content: error message
"""
print(content)
push_client.error_callback = error_callback