orca-sim
|
#include <NetBridge.hpp>
Public Member Functions | |
udp_client (const std::string &addr, int port) | |
Initialize a UDP client object. More... | |
~udp_client () | |
Clean up the UDP client object. More... | |
int | get_socket () const |
Retrieve a copy of the socket identifier. More... | |
int | get_port () const |
Retrieve the port used by this UDP client. More... | |
std::string | get_addr () const |
Retrieve a copy of the address. More... | |
int | send (const char *msg, size_t size) |
Send a message through this UDP client. More... | |
Private Attributes | |
int | f_socket |
int | f_port |
std::string | f_addr |
struct addrinfo * | f_addrinfo |
Definition at line 74 of file NetBridge.hpp.
udp_client::udp_client | ( | const std::string & | addr, |
int | port | ||
) |
Initialize a UDP client object.
This function initializes the UDP client object using the address and the port as specified.
The port is expected to be a host side port number (i.e. 59200).
The addr
parameter is a textual address. It may be an IPv4 or IPv6 address and it can represent a host name or an address defined with just numbers. If the address cannot be resolved then an error occurs and constructor throws.
udp_client_server_runtime_error | The server could not be initialized properly. Either the address cannot be resolved, the port is incompatible or not available, or the socket could not be created. |
[in] | addr | The address to convert to a numeric IP. |
[in] | port | The port number. |
Definition at line 380 of file NetBridge.cpp.
udp_client::~udp_client | ( | ) |
Clean up the UDP client object.
This function frees the address information structure and close the socket before returning.
Definition at line 412 of file NetBridge.cpp.
std::string udp_client::get_addr | ( | ) | const |
Retrieve a copy of the address.
This function returns a copy of the address as it was specified in the constructor. This does not return a canonalized version of the address.
The address cannot be modified. If you need to send data on a different address, create a new UDP client.
Definition at line 449 of file NetBridge.cpp.
int udp_client::get_port | ( | ) | const |
Retrieve the port used by this UDP client.
This function returns the port used by this UDP client. The port is defined as an integer, host side.
Definition at line 435 of file NetBridge.cpp.
int udp_client::get_socket | ( | ) | const |
Retrieve a copy of the socket identifier.
This function return the socket identifier as returned by the socket() function. This can be used to change some flags.
Definition at line 424 of file NetBridge.cpp.
int udp_client::send | ( | const char * | msg, |
size_t | size | ||
) |
Send a message through this UDP client.
This function sends msg
through the UDP client socket. The function cannot be used to change the destination as it was defined when creating the udp_client object.
The size must be small enough for the message to fit. In most cases we use these in Snap! to send very small signals (i.e. 4 bytes signalands.) Any data we would want to share remains in the Cassandra database so that way we can avoid losing it because of a UDP message.
[in] | msg | The message to send. |
[in] | size | The number of bytes representing this message. |
Definition at line 470 of file NetBridge.cpp.
|
private |
Definition at line 78 of file NetBridge.hpp.
|
private |
Definition at line 79 of file NetBridge.hpp.
|
private |
Definition at line 77 of file NetBridge.hpp.
|
private |
Definition at line 76 of file NetBridge.hpp.