Updated README with information about the timeouts

This commit is contained in:
GideonLeGrange 2015-03-30 16:43:00 +02:00
parent b02bf2eaee
commit eac62b0945
1 changed files with 30 additions and 0 deletions

View File

@ -76,6 +76,21 @@ To open an encrypted (TLS) connection is as simple, assuming the default API-SSL
ApiConnection con = ApiConnection.connectTLS("10.0.1.1"); // connect to router using TLS ApiConnection con = ApiConnection.connectTLS("10.0.1.1"); // connect to router using TLS
``` ```
By default, the API will generate an exception if it cannot connect to the specified router. This can take place immediately (typically if the router returns a 'Connection refused' error), but can also take up to 60 seconds if the router host is firewalled or if there are other network problems. This 60 seconds is the 'default connection timeout' an can be overridded by passing the preferred timeout to the APi as last parameter in a ```connect()``` or ```connectTLS()``` call. Here is the non-TLS example:
```java
ApiConnection con = ApiConnection.connect("10.0.1.1", ApiConnection.DEFAULT_PORT, 2000); // connect to router on the default API port and fail in 2 seconds
```
Connecting using TLS is similar:
```java
ApiConnection con = ApiConnection.connect("10.0.1.1", ApiConnection.DEFAULT_TLS_PORT, 2000); // connect to router on the default TLS API port and fail in 2 seconds
```
Note that ```ApiConnection.DEFAULT_PORT``` and ```ApiConnection.DEFAULT_TLS_PORT``` are provided to allow users who use the default ports to safely use the overloaded timeout method.
#### Notes about TLS: #### Notes about TLS:
* Currently only anonymous TLS is supported, not certificates. * Currently only anonymous TLS is supported, not certificates.
* There is a compatibility problem between the current versions of RouterOS supporting API over TLS and the Java Cryptography Extension (JCE) in Java 7 and earlier. TLS encryption works in Java 8 and later. For more information, feel free to contact me. * There is a compatibility problem between the current versions of RouterOS supporting API over TLS and the Java Cryptography Extension (JCE) in Java 7 and earlier. TLS encryption works in Java 8 and later. For more information, feel free to contact me.
@ -185,6 +200,21 @@ con.cancel(tag);
From version 2.0.0 of the API the error() and completed() methods are part of the ResultListener interface. From version 2.0.0 of the API the error() and completed() methods are part of the ResultListener interface.
Command timeouts
----------------
Command timeouts can be used to make sure that synchronous commands either return or fail within a specific time. Command timeouts are separate from the connection timeout used in ```connect()``` and ```connectTLS()```, and can be set using ```setTimeout()```. Here is an example:
```java
ApiConnection con = ApiConnection.connect("10.0.1.1"); // connect to router
con.setTimeout(5000); // set command timeout to 5 seconds
con.login("admin","password"); // log in to router
con.execute("/system/reboot"); // execute a command
```
It is important to note that command timeouts can be set before ```login()``` is called, and can therefore influence the behaviour of login.
The default command timeout, if none is set by the user, is 60 seconds.
References References
========== ==========