Main MRPT website > C++ reference for MRPT 1.5.9
Classes | Namespaces | Enumerations | Functions
Networking, sockets, DNS

Detailed Description

Collaboration diagram for Networking, sockets, DNS:

Classes

class  mrpt::utils::CClientTCPSocket
 A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing objects as well as generic read/write methods. More...
 
class  mrpt::utils::CServerTCPSocket
 A TCP socket that can be wait for client connections to enter. More...
 

Namespaces

 mrpt::utils::net
 A set of useful routines for networking.
 

Enumerations

enum  mrpt::utils::net::ERRORCODE_HTTP {
  mrpt::utils::net::erOk = 0, mrpt::utils::net::erBadURL, mrpt::utils::net::erCouldntConnect, mrpt::utils::net::erNotFound,
  mrpt::utils::net::erOtherHTTPError
}
 Possible returns from a HTTP request. More...
 

Functions

ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_get (const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
 Perform an HTTP GET operation (version for retrieving the data as a vector_byte) More...
 
ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_get (const string &url, string &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
 Perform an HTTP GET operation (version for retrieving the data as text) More...
 
ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_request (const string &http_method, const string &http_send_content, const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
 Generic function for HTTP GET & POST methods. More...
 
bool BASE_IMPEXP mrpt::utils::net::DNS_resolve_async (const std::string &server_name, std::string &out_ip, const unsigned int timeout_ms=3000)
 Resolve a server address by its name, returning its IP address as a string - This method has a timeout for the maximum time to wait for the DNS server. More...
 
std::string BASE_IMPEXP mrpt::utils::net::getLastSocketErrorStr ()
 Returns a description of the last Sockets error. More...
 
bool BASE_IMPEXP mrpt::utils::net::Ping (const std::string &address, const int &max_attempts, std::string *output_str=NULL)
 Ping an IP address. More...
 

Enumeration Type Documentation

◆ ERRORCODE_HTTP

Possible returns from a HTTP request.

Enumerator
erOk 
erBadURL 
erCouldntConnect 
erNotFound 
erOtherHTTPError 

Definition at line 31 of file net_utils.h.

Function Documentation

◆ DNS_resolve_async()

bool mrpt::utils::net::DNS_resolve_async ( const std::string server_name,
std::string out_ip,
const unsigned int  timeout_ms = 3000 
)

Resolve a server address by its name, returning its IP address as a string - This method has a timeout for the maximum time to wait for the DNS server.

For example: server_name="www.google.com" -> out_ip="209.85.227.99"

Returns
true on success, false on timeout or other error.

Definition at line 430 of file net_utils.cpp.

References mrpt::system::createThreadRef(), mrpt::system::joinThread(), and thread_DNS_solver_async().

Referenced by mrpt::utils::CClientTCPSocket::connect().

◆ getLastSocketErrorStr()

std::string mrpt::utils::net::getLastSocketErrorStr ( )

◆ http_get() [1/2]

ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_get ( const string url,
vector_byte out_content,
string out_errormsg,
int  port = 80,
const string auth_user = string(),
const string auth_pass = string(),
int *  out_http_responsecode = NULL,
mrpt::utils::TParameters< string > *  extra_headers = NULL,
mrpt::utils::TParameters< string > *  out_headers = NULL,
int  timeout_ms = 1000 
)

Perform an HTTP GET operation (version for retrieving the data as a vector_byte)

Parameters
urlMust be a simple string of the form "http://<servername>/<relative-address>".
portThe server port, if different from 80.
extra_headersIf provided, the given extra HTTP headers will be sent.
out_errormsgOn exit will contain a description of the error or "Ok".
out_contentThe buffer with the retrieved data.
out_http_responsecodeIf provided, will hold the HTTP code, eg: 200, 404...
out_headersIf provided, a copy of all the headers returned by the server will be saved here.
auth_userSend a basic HTTP authorization request with the given user & password.
auth_passSend a basic HTTP authorization request with the given user & password.
Returns
The error or success code.
See also
mrpt::utils::vectorToBinaryFile

Definition at line 388 of file net_utils.cpp.

References mrpt::utils::net::http_request().

Referenced by mrpt::hwdrivers::CRovio::captureImageAsync(), mrpt::hwdrivers::CRovio::general_command(), mrpt::utils::net::http_get(), mrpt::hwdrivers::CRovio::initialize(), mrpt::hwdrivers::CRovio::path_management(), mrpt::hwdrivers::CRovio::pathRename(), mrpt::hwdrivers::CNTRIPClient::retrieveListOfMountpoints(), and mrpt::hwdrivers::CRovio::send_cmd_action().

◆ http_get() [2/2]

ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_get ( const string url,
string out_content,
string out_errormsg,
int  port = 80,
const string auth_user = string(),
const string auth_pass = string(),
int *  out_http_responsecode = NULL,
mrpt::utils::TParameters< string > *  extra_headers = NULL,
mrpt::utils::TParameters< string > *  out_headers = NULL,
int  timeout_ms = 1000 
)

Perform an HTTP GET operation (version for retrieving the data as text)

Parameters
urlMust be a simple string of the form "http://<servername>/<relative-address>".
portThe server port, if different from 80.
extra_headersIf provided, the given extra HTTP headers will be sent.
out_errormsgOn exit will contain a description of the error or "Ok".
out_contentThe buffer with the retrieved data.
out_http_responsecodeIf provided, will hold the HTTP code, eg: 200, 404...
out_headersIf provided, a copy of all the headers returned by the server will be saved here.
auth_userSend a basic HTTP authorization request with the given user & password.
auth_passSend a basic HTTP authorization request with the given user & password.
Returns
The error or success code.
See also
mrpt::utils::vectorToBinaryFile

Definition at line 52 of file net_utils.cpp.

References mrpt::utils::net::http_get(), and mrpt::system::os::memcpy().

◆ http_request()

ERRORCODE_HTTP BASE_IMPEXP mrpt::utils::net::http_request ( const string http_method,
const string http_send_content,
const string url,
vector_byte out_content,
string out_errormsg,
int  port = 80,
const string auth_user = string(),
const string auth_pass = string(),
int *  out_http_responsecode = NULL,
mrpt::utils::TParameters< string > *  extra_headers = NULL,
mrpt::utils::TParameters< string > *  out_headers = NULL,
int  timeout_ms = 1000 
)

◆ Ping()

bool mrpt::utils::net::Ping ( const std::string address,
const int &  max_attempts,
std::string output_str = NULL 
)

Ping an IP address.

Parameters
[in]addressAddress to ping.
[in]max_attemptsNumber of attempts to try and ping.
[out]outputString containing output information
Returns
True if responsive, false otherwise.
Note
{ I am redirecting stderr to stdout, so that the overall process is simplified. Otherwise see: https://jineshkj.wordpress.com/2006/12/22/how-to-capture-stdin-stdout-and-stderr-of-child-program/ }

Definition at line 538 of file net_utils.cpp.

References mrpt::system::executeCommand(), mrpt::mrpt::format(), mrpt::system::num2str(), and THROW_EXCEPTION.




Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020