diff --git a/lib/socket_.py b/lib/socket_.py index 9028c53..20528f8 100644 --- a/lib/socket_.py +++ b/lib/socket_.py @@ -128,7 +128,7 @@ class MessageSocketClient(WebSocketClient): self._io_loop = ioloop.IOLoop.current() self.ws_url = None self.auto_net = False - self.heartbeat_interval_in_secs = 30 + self.heartbeat_interval_in_secs = 3 super(MessageSocketClient, self).__init__(self._io_loop, self.connect_timeout, @@ -161,7 +161,7 @@ class MessageSocketClient(WebSocketClient): if self._connect_success: self._connect_success(self) self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs, - functools.partial(self.sendheartbeat)) + functools.partial(self.sendheartbeat, self.ws_url)) def on_connection_close(self, reason): print('%s Connection closed reason=%s' % (self.ws_url, reason,)) @@ -178,14 +178,16 @@ class MessageSocketClient(WebSocketClient): def payload_data(self): return {"type": "ping"} - def sendheartbeat(self): + def sendheartbeat(self, _url): print(datetime.datetime.now(), "发送❤️") - msg = self.payload_data() - bool = self.send(msg) if msg else False - - if msg is None or bool: - self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs, - functools.partial(self.sendheartbeat)) + if self.ws_url == _url: + msg = self.payload_data() + bool = self.send(msg) if msg else False + + if msg is None or bool: + self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs, + functools.partial(self.sendheartbeat, + self.ws_url)) def on_message(self, msg): if not self._message_receive: