Class TCPSocket

Inheritance Relationships

Derived Types

Class Documentation

class TCPSocket

Class for TCP socket abstraction.

Subclassed by urcl::comm::URStream< urcl::rtde_interface::RTDEPackage >, urcl::DashboardClient, urcl::comm::URStream< T >

Public Functions

TCPSocket()

Creates a TCPSocket object.

virtual ~TCPSocket()
inline SocketState getState()

Getter for the state of the socket.

Returns:

Returns the current state of the socket

inline int getSocketFD()

Getter for the file descriptor of the socket.

Returns:

The file descriptor of the socket

std::string getIP() const

Determines the local IP address of the currently configured socket.

Returns:

The local IP address of the socket associated to the current file descriptor

bool read(char *character)

Reads one byte from the socket.

Parameters:

character[out] Target buffer

Returns:

True on success, false otherwise

bool read(uint8_t *buf, const size_t buf_len, size_t &read)

Reads data from the socket.

Parameters:
  • buf[out] Buffer where the data shall be stored

  • buf_len[in] Number of bytes allocated for the buffer

  • read[out] Number of bytes actually read

Returns:

True on success, false otherwise

bool write(const uint8_t *buf, const size_t buf_len, size_t &written)

Writes to the socket.

Parameters:
  • buf[in] Buffer of bytes to write

  • buf_len[in] Number of bytes in the buffer

  • written[out] Number of bytes actually written

Returns:

True on success, false otherwise

void close()

Closes the connection to the socket.

void setReceiveTimeout(const timeval &timeout)

Setup Receive timeout used for this socket.

Parameters:

timeout – Timeout used for setting things up

void setReconnectionTime(const std::chrono::milliseconds reconnection_time)

Set reconnection time, if the server is unavailable during connection this will set the time before trying connect to the server again.

Parameters:

reconnection_time – time in between connection attempts to the server

Public Static Attributes

static constexpr std::chrono::milliseconds DEFAULT_RECONNECTION_TIME = {10000}

Protected Functions

bool setup(const std::string &host, const int port, const size_t max_num_tries = 0, const std::chrono::milliseconds reconnection_time = DEFAULT_RECONNECTION_TIME)

Protected Attributes

std::unique_ptr<timeval> recv_timeout_

Protected Static Functions

static inline bool open(int socket_fd, struct sockaddr *address, size_t address_len)