2525 */
2626use PEAR2 \Net \Transmitter \Stream as S ;
2727
28+ /**
29+ * Refers to the cryptography constants.
30+ */
31+ use PEAR2 \Net \Transmitter \NetworkStream AS N ;
32+
2833/**
2934 * A RouterOS client.
3035 *
@@ -96,11 +101,18 @@ class Client
96101 * @param string $host Hostname (IP or domain) of the RouterOS server.
97102 * @param string $username The RouterOS username.
98103 * @param string $password The RouterOS password.
99- * @param int $port The port on which the RouterOS server provides
100- * the API service.
104+ * @param int|null $port The port on which the RouterOS server provides
105+ * the API service. You can also specify NULL, in which case the port
106+ * will automatically be chosen between 8728 and 8729, depending on your
107+ * encryption setting.
101108 * @param bool $persist Whether or not the connection should be a
102109 * persistent one.
103110 * @param float $timeout The timeout for the connection.
111+ * @param string $crypto The encryption for this connection. Must be one
112+ * of the PEAR2\Net\Transmitter\NetworkStream::CRYPTO_* constants. Off
113+ * by default. For the sake of simplicity, if you specify an encryption,
114+ * don't specify a context and your default context uses the value
115+ * "DEFAULT" for ciphers, "ADH" will be automatically added to the list.
104116 * @param resource $context A context for the socket.
105117 *
106118 * @see sendSync()
@@ -113,6 +125,7 @@ public function __construct(
113125 $ port = 8728 ,
114126 $ persist = false ,
115127 $ timeout = null ,
128+ $ crypto = N::CRYPTO_OFF ,
116129 $ context = null
117130 ) {
118131 $ this ->com = new Communicator (
@@ -121,6 +134,7 @@ public function __construct(
121134 $ persist ,
122135 $ timeout ,
123136 $ username . '/ ' . $ password ,
137+ $ crypto ,
124138 $ context
125139 );
126140 $ timeout = null == $ timeout
@@ -695,7 +709,8 @@ public function close()
695709 $ result = $ response ->getType () === Response::TYPE_FATAL ;
696710 $ result = $ result && $ this ->com ->close ();
697711 } catch (SocketException $ e ) {
698- $ result = $ e ->getCode () === 40900 ;
712+ $ result
713+ = $ e ->getCode () === SocketException::CODE_UNACCEPTING_REQEUST ;
699714 if (null !== $ this ->registry ) {
700715 $ this ->registry ->setTaglessMode (false );
701716 }
0 commit comments