@@ -157,8 +157,7 @@ def connect(self):
157157 Extra information:
158158 Use this function to reconnect to the RCON server after an error.
159159 """
160- if self .rcon_socket is not None :
161- self .rcon_socket .close ()
160+ self .close ()
162161 self .rcon_failure = False
163162 self .rcon_socket = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
164163 self .rcon_socket .settimeout (self .timeout )
@@ -368,8 +367,7 @@ async def connect(self):
368367 Extra information:
369368 Use this function to reconnect to the RCON server after an error.
370369 """
371- if self .rcon_socket is not None :
372- await self .rcon_socket .close ()
370+ await self .close ()
373371 self .rcon_failure = False
374372 try :
375373 self .rcon_socket = await anyio .connect_tcp (self .ip_address , self .port )
@@ -403,7 +401,7 @@ async def close(self):
403401 After closing, the client can still be reconnected using .connect().
404402 """
405403 if self .rcon_socket is not None :
406- await self .rcon_socket .close ()
404+ await self .rcon_socket .aclose ()
407405 self .rcon_socket = None
408406
409407 async def send_packet (self , packet_id , packet_type , packet_body ):
@@ -422,7 +420,7 @@ async def send_packet(self, packet_id, packet_type, packet_body):
422420 """
423421 packet = PACKET_PARSER .build ([dict (id = packet_id , type = packet_type , body = packet_body )])
424422 try :
425- await self .rcon_socket .send_all (packet )
423+ await self .rcon_socket .send (packet )
426424 except Exception as exc :
427425 raise RCONSendError (SEND_ERROR ) from exc
428426
@@ -443,10 +441,10 @@ async def receive_packets(self):
443441 try :
444442 data = b""
445443 while True :
446- read_data = await self . rcon_socket . receive_some ( 4096 )
447- if not read_data :
448- raise RCONClosed ( CONN_CLOSED )
449- data += read_data
444+ try :
445+ data += await self . rcon_socket . receive ()
446+ except anyio . EndOfStream as exc :
447+ raise RCONClosed ( CONN_CLOSED ) from exc
450448 if len (data ) > 2 :
451449 if data .endswith (b"\x00 \x00 " ):
452450 break
0 commit comments