diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 4b1516ad9..9d17e7695 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -49,10 +49,16 @@ class OpenOcd: self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def __enter__(self): - self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + self.connect() return self def __exit__(self, type, value, traceback): + self.disconnect() + + def connect(self): + self.sock.connect((self.tclRpcIp, self.tclRpcPort)) + + def disconnect(self): try: self.send("exit") finally: