作者 lemon

更新代码2

@@ -128,7 +128,7 @@ class MessageSocketClient(WebSocketClient): @@ -128,7 +128,7 @@ class MessageSocketClient(WebSocketClient):
128 self._io_loop = ioloop.IOLoop.current() 128 self._io_loop = ioloop.IOLoop.current()
129 self.ws_url = None 129 self.ws_url = None
130 self.auto_net = False 130 self.auto_net = False
131 - self.heartbeat_interval_in_secs = 30 131 + self.heartbeat_interval_in_secs = 3
132 132
133 super(MessageSocketClient, self).__init__(self._io_loop, 133 super(MessageSocketClient, self).__init__(self._io_loop,
134 self.connect_timeout, 134 self.connect_timeout,
@@ -161,7 +161,7 @@ class MessageSocketClient(WebSocketClient): @@ -161,7 +161,7 @@ class MessageSocketClient(WebSocketClient):
161 if self._connect_success: 161 if self._connect_success:
162 self._connect_success(self) 162 self._connect_success(self)
163 self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs, 163 self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs,
164 - functools.partial(self.sendheartbeat)) 164 + functools.partial(self.sendheartbeat, self.ws_url))
165 165
166 def on_connection_close(self, reason): 166 def on_connection_close(self, reason):
167 print('%s Connection closed reason=%s' % (self.ws_url, reason,)) 167 print('%s Connection closed reason=%s' % (self.ws_url, reason,))
@@ -178,14 +178,16 @@ class MessageSocketClient(WebSocketClient): @@ -178,14 +178,16 @@ class MessageSocketClient(WebSocketClient):
178 def payload_data(self): 178 def payload_data(self):
179 return {"type": "ping"} 179 return {"type": "ping"}
180 180
181 - def sendheartbeat(self): 181 + def sendheartbeat(self, _url):
182 print(datetime.datetime.now(), "发送❤️") 182 print(datetime.datetime.now(), "发送❤️")
  183 + if self.ws_url == _url:
183 msg = self.payload_data() 184 msg = self.payload_data()
184 bool = self.send(msg) if msg else False 185 bool = self.send(msg) if msg else False
185 186
186 if msg is None or bool: 187 if msg is None or bool:
187 self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs, 188 self._later_handler['heartbeat'] = self._io_loop.call_later(self.heartbeat_interval_in_secs,
188 - functools.partial(self.sendheartbeat)) 189 + functools.partial(self.sendheartbeat,
  190 + self.ws_url))
189 191
190 def on_message(self, msg): 192 def on_message(self, msg):
191 if not self._message_receive: 193 if not self._message_receive: