@@ -342,9 +342,9 @@ def get_socket(self):
342342 raise RuntimeError ("No sockets available" )
343343 return resp
344344
345- def start_client (self , dest , ip , port , socket_num , conn_mode = TCP_MODE ):
345+ def socket_open (self , dest , ip , port , socket_num , conn_mode = TCP_MODE ):
346346 if self ._debug :
347- print ("*** Start Client " )
347+ print ("*** Open socket " )
348348 port_param = struct .pack ('>H' , port )
349349 resp = self .send_command_get_response (START_CLIENT_TCP_CMD ,
350350 [ip , port_param ,
@@ -387,10 +387,15 @@ def socket_connect(self, dest, port):
387387 if self ._debug :
388388 print ("Allocated socket #%d" % self .sock_num )
389389
390- self .start_client (dest , dest , port , self .sock_num )
390+ self .socket_open (dest , dest , port , self .sock_num )
391391 times = time .monotonic ()
392392 while (time .monotonic () - times ) < 3 : # wait 3 seconds
393393 if self .socket_connected (self .sock_num ):
394394 return
395395 time .sleep (0.01 )
396396 raise RuntimeError ("Failed to establish connection" )
397+
398+ def socket_close (self , socket_num ):
399+ resp = self .send_command_get_response (STOP_CLIENT_TCP_CMD , [[socket_num ]])
400+ if resp [0 ][0 ] != 1 :
401+ raise RuntimeError ("Failed to close socket" )
0 commit comments