@@ -342,9 +342,9 @@ def get_socket(self):
342
342
raise RuntimeError ("No sockets available" )
343
343
return resp
344
344
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 ):
346
346
if self ._debug :
347
- print ("*** Start Client " )
347
+ print ("*** Open socket " )
348
348
port_param = struct .pack ('>H' , port )
349
349
resp = self .send_command_get_response (START_CLIENT_TCP_CMD ,
350
350
[ip , port_param ,
@@ -387,10 +387,15 @@ def socket_connect(self, dest, port):
387
387
if self ._debug :
388
388
print ("Allocated socket #%d" % self .sock_num )
389
389
390
- self .start_client (dest , dest , port , self .sock_num )
390
+ self .socket_open (dest , dest , port , self .sock_num )
391
391
times = time .monotonic ()
392
392
while (time .monotonic () - times ) < 3 : # wait 3 seconds
393
393
if self .socket_connected (self .sock_num ):
394
394
return
395
395
time .sleep (0.01 )
396
396
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