@@ -257,8 +257,8 @@ def connect(self, clean_session=True):
257
257
self .logger .debug ('Sending CONNECT to broker' )
258
258
self .logger .debug ('Fixed Header: {}\n Variable Header: {}' .format (fixed_header ,
259
259
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 )
262
262
# [MQTT-3.1.3-4]
263
263
self ._send_str (self .client_id )
264
264
if self ._lw_topic :
@@ -291,7 +291,7 @@ def disconnect(self):
291
291
self .is_connected ()
292
292
if self .logger is not None :
293
293
self .logger .debug ('Sending DISCONNECT packet to broker' )
294
- self ._sock .write (MQTT_DISCONNECT )
294
+ self ._sock .send (MQTT_DISCONNECT )
295
295
if self .logger is not None :
296
296
self .logger .debug ('Closing socket' )
297
297
self ._sock .close ()
@@ -307,7 +307,7 @@ def ping(self):
307
307
self .is_connected ()
308
308
if self .logger is not None :
309
309
self .logger .debug ('Sending PINGREQ' )
310
- self ._sock .write (MQTT_PINGREQ )
310
+ self ._sock .send (MQTT_PINGREQ )
311
311
if self .logger is not None :
312
312
self .logger .debug ('Checking PINGRESP' )
313
313
while True :
@@ -375,7 +375,7 @@ def publish(self, topic, msg, retain=False, qos=0):
375
375
if self .logger is not None :
376
376
self .logger .debug ('Sending PUBLISH\n Topic: {0}\n Msg: {1}\
377
377
\n QoS: {2}\n Retain? {3}' .format (topic , msg , qos , retain ))
378
- self ._sock .write (pkt )
378
+ self ._sock .send (pkt )
379
379
self ._send_str (topic )
380
380
if qos == 0 :
381
381
if self .on_publish is not None :
@@ -384,12 +384,12 @@ def publish(self, topic, msg, retain=False, qos=0):
384
384
self ._pid += 1
385
385
pid = self ._pid
386
386
struct .pack_into ("!H" , pkt , 0 , pid )
387
- self ._sock .write (pkt )
387
+ self ._sock .send (pkt )
388
388
if self .on_publish is not None :
389
389
self .on_publish (self , self .user_data , topic , pid )
390
390
if self .logger is not None :
391
391
self .logger .debug ('Sending PUBACK' )
392
- self ._sock .write (msg )
392
+ self ._sock .send (msg )
393
393
if qos == 1 :
394
394
while True :
395
395
op = self ._wait_for_msg ()
@@ -468,7 +468,7 @@ def subscribe(self, topic, qos=0):
468
468
if self .logger is not None :
469
469
for t , q in topics :
470
470
self .logger .debug ('SUBSCRIBING to topic {0} with QoS {1}' .format (t , q ))
471
- self ._sock .write (packet )
471
+ self ._sock .send (packet )
472
472
while True :
473
473
op = self ._wait_for_msg ()
474
474
if op == 0x90 :
@@ -523,7 +523,7 @@ def unsubscribe(self, topic):
523
523
if self .logger is not None :
524
524
for t in topics :
525
525
self .logger .debug ('UNSUBSCRIBING from topic {0}.' .format (t ))
526
- self ._sock .write (packet )
526
+ self ._sock .send (packet )
527
527
if self .logger is not None :
528
528
self .logger .debug ('Waiting for UNSUBACK...' )
529
529
while True :
@@ -666,7 +666,7 @@ def _wait_for_msg(self, timeout=30):
666
666
if res [0 ] & 0x06 == 0x02 :
667
667
pkt = bytearray (b"\x40 \x02 \0 \0 " )
668
668
struct .pack_into ("!H" , pkt , 2 , pid )
669
- self ._sock .write (pkt )
669
+ self ._sock .send (pkt )
670
670
elif res [0 ] & 6 == 4 :
671
671
assert 0
672
672
return res [0 ]
@@ -685,11 +685,11 @@ def _send_str(self, string):
685
685
"""Packs and encodes a string to a socket.
686
686
:param str string: String to write to the socket.
687
687
"""
688
- self ._sock .write (struct .pack ("!H" , len (string )))
688
+ self ._sock .send (struct .pack ("!H" , len (string )))
689
689
if isinstance (string , str ):
690
- self ._sock .write (str .encode (string , 'utf-8' ))
690
+ self ._sock .send (str .encode (string , 'utf-8' ))
691
691
else :
692
- self ._sock .write (string )
692
+ self ._sock .send (string )
693
693
694
694
@staticmethod
695
695
def _check_topic (topic ):
0 commit comments