Pergunta

I'm using MATLAB to connect to a database hosted in AWS (using the database toolbox). In order to do that, I supply the URL of the database as a local port and create a SSH tunnel to the AWS host.

The issue is that this tunnel needs to be created in order for the code to run. If it is not, no error message is generated but MATLAB gets hung and needs to be killed. I would like to deploy this code to users who will not be able to troubleshoot if this tunnel is missing.

My question is: is there a way to check for a local port opening in MATLAB? How would I check if the tunnel is setup?

Foi útil?

Solução

Since you are using the Database Toolbox, you might want to use the logintimeout function. As the documentation says:

Note If you do not specify a value for logintimeout and the MATLAB session cannot establish a database connection, your MATLAB session may freeze.

And you would wrap your code inside a try/catch block

Outras dicas

I am not familiar with Matlab's TCP objects, but there is a system command that executes a program, returning its exit code (see its documentation). So what would probably do the job is a small program or script (as portable as needed), that tries to connect to the local port.

Alternatively, the small program/script could actually open (or re-open) the tunnel and return 0 on success. (This possibly adds the problem of how Matlab handles forking processes, I don't know how it handles that.)

There probably is some way to do the check if open and re-open if not-housekeeping via Matlab, but I have no clue.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top