Skip to content

Commit 5c953e2

Browse files
authored
Merge pull request adafruit#7 from brentru/sock-send
Switch to Socket.Send
2 parents b6429df + 9914310 commit 5c953e2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

adafruit_minimqtt.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ def connect(self, clean_session=True):
257257
self.logger.debug('Sending CONNECT to broker')
258258
self.logger.debug('Fixed Header: {}\nVariable Header: {}'.format(fixed_header,
259259
var_header))
260-
self._sock.write(fixed_header)
261-
self._sock.write(var_header)
260+
self._sock.send(fixed_header)
261+
self._sock.send(var_header)
262262
# [MQTT-3.1.3-4]
263263
self._send_str(self.client_id)
264264
if self._lw_topic:
@@ -291,7 +291,7 @@ def disconnect(self):
291291
self.is_connected()
292292
if self.logger is not None:
293293
self.logger.debug('Sending DISCONNECT packet to broker')
294-
self._sock.write(MQTT_DISCONNECT)
294+
self._sock.send(MQTT_DISCONNECT)
295295
if self.logger is not None:
296296
self.logger.debug('Closing socket')
297297
self._sock.close()
@@ -307,7 +307,7 @@ def ping(self):
307307
self.is_connected()
308308
if self.logger is not None:
309309
self.logger.debug('Sending PINGREQ')
310-
self._sock.write(MQTT_PINGREQ)
310+
self._sock.send(MQTT_PINGREQ)
311311
if self.logger is not None:
312312
self.logger.debug('Checking PINGRESP')
313313
while True:
@@ -375,7 +375,7 @@ def publish(self, topic, msg, retain=False, qos=0):
375375
if self.logger is not None:
376376
self.logger.debug('Sending PUBLISH\nTopic: {0}\nMsg: {1}\
377377
\nQoS: {2}\nRetain? {3}'.format(topic, msg, qos, retain))
378-
self._sock.write(pkt)
378+
self._sock.send(pkt)
379379
self._send_str(topic)
380380
if qos == 0:
381381
if self.on_publish is not None:
@@ -384,12 +384,12 @@ def publish(self, topic, msg, retain=False, qos=0):
384384
self._pid += 1
385385
pid = self._pid
386386
struct.pack_into("!H", pkt, 0, pid)
387-
self._sock.write(pkt)
387+
self._sock.send(pkt)
388388
if self.on_publish is not None:
389389
self.on_publish(self, self.user_data, topic, pid)
390390
if self.logger is not None:
391391
self.logger.debug('Sending PUBACK')
392-
self._sock.write(msg)
392+
self._sock.send(msg)
393393
if qos == 1:
394394
while True:
395395
op = self._wait_for_msg()
@@ -468,7 +468,7 @@ def subscribe(self, topic, qos=0):
468468
if self.logger is not None:
469469
for t, q in topics:
470470
self.logger.debug('SUBSCRIBING to topic {0} with QoS {1}'.format(t, q))
471-
self._sock.write(packet)
471+
self._sock.send(packet)
472472
while True:
473473
op = self._wait_for_msg()
474474
if op == 0x90:
@@ -523,7 +523,7 @@ def unsubscribe(self, topic):
523523
if self.logger is not None:
524524
for t in topics:
525525
self.logger.debug('UNSUBSCRIBING from topic {0}.'.format(t))
526-
self._sock.write(packet)
526+
self._sock.send(packet)
527527
if self.logger is not None:
528528
self.logger.debug('Waiting for UNSUBACK...')
529529
while True:
@@ -666,7 +666,7 @@ def _wait_for_msg(self, timeout=30):
666666
if res[0] & 0x06 == 0x02:
667667
pkt = bytearray(b"\x40\x02\0\0")
668668
struct.pack_into("!H", pkt, 2, pid)
669-
self._sock.write(pkt)
669+
self._sock.send(pkt)
670670
elif res[0] & 6 == 4:
671671
assert 0
672672
return res[0]
@@ -685,11 +685,11 @@ def _send_str(self, string):
685685
"""Packs and encodes a string to a socket.
686686
:param str string: String to write to the socket.
687687
"""
688-
self._sock.write(struct.pack("!H", len(string)))
688+
self._sock.send(struct.pack("!H", len(string)))
689689
if isinstance(string, str):
690-
self._sock.write(str.encode(string, 'utf-8'))
690+
self._sock.send(str.encode(string, 'utf-8'))
691691
else:
692-
self._sock.write(string)
692+
self._sock.send(string)
693693

694694
@staticmethod
695695
def _check_topic(topic):

0 commit comments

Comments
 (0)