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

Module network

source code

Warning: do not use this library. It is unstable and most of the routines here have been superceded by other libraries (e.g. rosgraph). These routines will likely be *deleted* in future releases.

Classes
  ROSHandshakeException
Exception to represent errors decoding handshake
Functions
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
  ROS_IP = 'ROS_IP'
  ROS_HOSTNAME = 'ROS_HOSTNAME'
  SIOCGIFADDR = 35093
  SIOCGIFCONF = 35090
  __package__ = 'roslib'
Function Details

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)