Can't connect to Router ( public IP )

Hello everyone,

I have encountered a problem with Pear2_Net_RouterOS API when connecting to a Router using its public IP… The website that I used are being hosted at cPanel, I tried connecting it with the local/private network, and the API can connect to the public IP of the router without a problem…

exception 'PEAR2\Net\Transmitter\SocketException' with message 'stream_socket_client(): unable to connect to tcp://203.177.22.157:8728/api%2FaPi%40ccess%4017 (Failed to parse address "203.177.22.157:8728/api%2FaPi%40ccess%4017")' in /www/wp-content/plugins/dev-tools/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 /www/wp-content/plugins/dev-tools/PEAR2/Net/Transmitter/Stream.php(130): PEAR2\Net\Transmitter\TcpClient->createException('stream_socket_c...', 0) #1 [internal function]: PEAR2\Net\Transmitter\Stream->handleError(2, 'stream_socket_c...', '/www/wp-content...', 147, Array) #2 /www/wp-content/plugins/dev-tools/PEAR2/Net/Transmitter/TcpClient.php(147): stream_socket_client('tcp://203.177.2...', 0, 'Failed to parse...', 3, 4, Resource id #2) #3 /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('203.177.22.157', 8728, false, 3, 'api/aPi@ccess@1...', '', NULL) #4 /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('203.177.22.157', NULL, false, 3, 'api/aPi@ccess@1...', '', NULL) #5 /www/wp-content/plugins/dev-tools/functions-dev.php(44): PEAR2\Net\RouterOS\Client->__construct('203.177.22.157', 'api', 'aPi@ccess@17', NULL, false, 3) #6 /www/wp-admin/includes/plugin.php(1882): include('/www/wp-content...') #7 /www/wp-admin/plugins.php(164): plugin_sandbox_scrape('dev-tools/funct...') #8 {main} Next exception 'PEAR2\Net\Transmitter\SocketException' with message 'Failed to initialize socket.' in /www/wp-content/plugins/dev-tools/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 /www/wp-content/plugins/dev-tools/PEAR2/Net/Transmitter/TcpClient.php(157): PEAR2\Net\Transmitter\TcpClient->createException('Failed to initi...', 7, Object(PEAR2\Net\Transmitter\SocketException)) #1 /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('203.177.22.157', 8728, false, 3, 'api/aPi@ccess@1...', '', NULL) #2 /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('203.177.22.157', NULL, false, 3, 'api/aPi@ccess@1...', '', NULL) #3 /www/wp-content/plugins/dev-tools/functions-dev.php(44): PEAR2\Net\RouterOS\Client->__construct('203.177.22.157', 'api', 'aPi@ccess@17', NULL, false, 3) #4 /www/wp-admin/includes/plugin.php(1882): include('/www/wp-content...') #5 /www/wp-admin/plugins.php(164): plugin_sandbox_scrape('dev-tools/funct...') #6 {main} Next exception 'PEAR2\Net\RouterOS\SocketException' with message 'Error connecting to RouterOS' in /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Communicator.php:150 Stack trace: #0 /www/wp-content/plugins/dev-tools/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('203.177.22.157', NULL, false, 3, 'api/aPi@ccess@1...', '', NULL) #1 /www/wp-content/plugins/dev-tools/functions-dev.php(44): PEAR2\Net\RouterOS\Client->__construct('203.177.22.157', 'api', 'aPi@ccess@17', NULL, false, 3) #2 /www/wp-admin/includes/plugin.php(1882): include('/www/wp-content...') #3 /www/wp-admin/plugins.php(164): plugin_sandbox_scrape('dev-tools/funct...') #4 {main}

here’s the error …

Here’s the code that I used to connect to it

use PEAR2\Net\RouterOS;
require_once( dirname(__FILE__) . '/PEAR2/Autoload.php' );

try {
$client = new RouterOS\Client('203.177.22.157', 'username_router', 'password_router', null, false, 3);
    echo 'OK';
} catch (Exception $e) {
    die($e);
}

https://github.com/pear2/Net_RouterOS/issues/27