Package roslib :: Module network
[frames] | no frames]

Module network

source code

Network APIs for ROS-based systems, including IP address and ROS TCP header libraries. Because ROS-based runtimes must respect the ROS_IP and ROS_HOSTNAME environment variables, ROS-specific APIs are necessary for correctly retrieving local IP address information.

roslib.network supports the netifaces library as an optional add-on. netifaces improves IP address configuration detection.

Classes
  ROSHandshakeException
Exception to represent errors decoding handshake
Functions
(str, int)
parse_http_host_and_port(url)
Convenience routine to handle parsing and validation of HTTP URL port due to the fact that Python only provides easy accessors in Python 2.5 and later.
source code
str
get_address_override()
Returns: ROS_IP/ROS_HOSTNAME override or None
source code
 
is_local_address(hostname) source code
str
get_local_address()
Returns: default local IP address (e.g.
source code
[str]
get_local_addresses()
Returns: known local addresses.
source code
str
get_bind_address(address=None)
Returns: address TCP/IP sockets should use for binding.
source code
 
get_host_name()
Determine host-name for use in host-name-based addressing (e.g.
source code
str
create_local_xmlrpc_uri(port)
Determine the XMLRPC URI for local servers.
source code
{str: str}
decode_ros_handshake_header(header_str)
Decode serialized ROS handshake header into a Python dictionary
source code
{str: str}
read_ros_handshake_header(sock, b, buff_size)
Read in tcpros header off the socket  sock using buffer  b.
source code
str
encode_ros_handshake_header(header)
Encode ROS handshake header as a byte string.
source code
int
write_ros_handshake_header(sock, header)
Write ROS handshake header header to socket sock
source code
Variables
  python3 = 0
  SIOCGIFADDR = 35093
  SIOCGIFCONF = 35090
  __package__ = 'roslib'
Function Details

parse_http_host_and_port(url)

source code 

Convenience routine to handle parsing and validation of HTTP URL port due to the fact that Python only provides easy accessors in Python 2.5 and later. Validation checks that the protocol and host are set.

Parameters:
  • url (str) - URL to parse
Returns: (str, int)
hostname and port number in URL or 80 (default).
Raises:
  • ValueError - if the url does not validate

get_address_override()

source code 
Returns: str
ROS_IP/ROS_HOSTNAME override or None
Raises:
  • ValueError - if ROS_IP/ROS_HOSTNAME/__ip/__hostname are invalidly specified

is_local_address(hostname)

source code 
Parameters:
  • hostname (str) - host name/address

get_local_address()

source code 
Returns: str
default local IP address (e.g. eth0). May be overriden by ROS_IP/ROS_HOSTNAME/__ip/__hostname

get_local_addresses()

source code 
Returns: [str]
known local addresses. Not affected by ROS_IP/ROS_HOSTNAME

get_bind_address(address=None)

source code 
Parameters:
  • address (str) - (optional) address to compare against
Returns: str
address TCP/IP sockets should use for binding. This is generally 0.0.0.0, but if  address or ROS_IP/ROS_HOSTNAME is set to localhost it will return 127.0.0.1

get_host_name()

source code 

Determine host-name for use in host-name-based addressing (e.g. XML-RPC URIs):

  • if ROS_IP/ROS_HOSTNAME is set, use that address
  • if the hostname returns a non-localhost value, use that
  • use whatever get_local_address() returns

create_local_xmlrpc_uri(port)

source code 

Determine the XMLRPC URI for local servers. This handles the search logic of checking ROS environment variables, the known hostname, and local interface IP addresses to determine the best possible URI.

Parameters:
  • port (int) - port that server is running on
Returns: str
XMLRPC URI

decode_ros_handshake_header(header_str)

source code 

Decode serialized ROS handshake header into a Python dictionary

header is a list of string key=value pairs, each prefixed by a 4-byte length field. It is preceeded by a 4-byte length field for the entire header.

Parameters:
  • header_str (str) - encoded header string. May contain extra data at the end.
Returns: {str: str}
key value pairs encoded in  header_str

read_ros_handshake_header(sock, b, buff_size)

source code 

Read in tcpros header off the socket  sock using buffer  b.

Parameters:
  • sock (socket) - socket must be in blocking mode
  • b (StringIO for Python2, BytesIO for Python 3) - buffer to use
  • buff_size (int) - incoming buffer size to use
Returns: {str: str}
key value pairs encoded in handshake
Raises:

encode_ros_handshake_header(header)

source code 

Encode ROS handshake header as a byte string. Each header field is a string key value pair. The encoded header is prefixed by a length field, as is each field key/value pair. key/value pairs a separated by a '=' equals sign.

FORMAT: (4-byte length + [4-byte field length + field=value ]*)

Parameters:
  • header (dict) - header field keys/values
Returns: str
header encoded as byte string

write_ros_handshake_header(sock, header)

source code 

Write ROS handshake header header to socket sock

Parameters:
  • sock (socket.socket) - socket to write to (must be in blocking mode)
  • header ({str : str}) - header field keys/values
Returns: int
Number of bytes sent (for statistics)