def get_my_sid(sid): print(sid) data = { 'sid': sid, } code = 'ack_send_sid' Relay.send_msg(sid, code, data) return
def update_heart_beat(self, sid): if sid in self._admin_dict: self._admin_dict[sid] = int(time.time()) return user = self.get_user_by_sid(sid) if user == None: Relay.send_disconnect(sid) else: user.update_heart_beat() return
def push_info(sid, data): # Data.find() if Relay.is_admin(sid) is False: return user_id = data['user_id'] user = Relay.get_user(user_id) if user is None: return msg = data['msg'] Relay.send_msg_by_user_id(user.get_id(), 'ACK_PUSH', msg) return
def update(self): del_list = list() for user_id, user in self._user_dict.items(): if user.has_heartbeat() is True: continue del_list.append(user_id) for user_id in del_list: Relay.user_exit(user_id) # 更新用户管理器 exit_admin = [] for admin_sid, last_connect_time in self._admin_dict.items(): if int(time.time()) - last_connect_time > 10: exit_admin.append(admin_sid) for i in exit_admin: self._admin_dict.pop(i) print('管理员', i, '长时间无心跳,已被杀死') return
def user_exit(sid): if Relay.is_admin(sid) == True: Relay.kill_admin(sid) print('这个http服务器的管理员退出了', sid) return user = Relay.get_user_by_sid(sid) if user is not None: user_id = user.get_id() Relay.user_exit(user_id) print('这个普通用户退出了', sid) print(sid, '退出了推送系统') return
def login(sid, data): phone = data['phone'] pw = data['passwd'] user_info = Data.find('openluat_user', [('phone', '=', phone)]) if user_info is None: Relay.send_error(sid) if check_password_hash(pw, user_info['password_hash']) != True: Relay.send_error(sid) user_id = user_info['id'] Relay.user_login(sid, user_id) return
def __init__(self, host, port): SocketIOBase.__init__(self, host, port) self.user_manager = UserManager() Relay.init(self) # 放在函数尾部 return
def heart_beat(sid): Relay.update_status(sid) return
def req_test(sid, data): print('收到http服务器的推送', sid) print(Relay.get_all_admin()) # CountdownTask(5,Relay.send_msg,(sid, 'ack_test', data)) data['comment'] = 'socketio_server Callback' Relay.send_msg(sid, 'ack_test', data)
def connect_push_system(sid): # Data.find() Relay.connect_push_system(sid) return