AWS SDK for C++

AWS SDK for C++ Version 1.11.792

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Aws::Net::SimpleUDP Class Reference

#include <SimpleUDP.h>

Public Member Functions

 SimpleUDP (int addressFamily, size_t sendBufSize=UDP_BUFFER_SIZE, size_t receiveBufSize=UDP_BUFFER_SIZE, bool nonBlocking=true)
 Constructor of SimpleUDP.
 
 SimpleUDP (bool IPV4=true, size_t sendBufSize=UDP_BUFFER_SIZE, size_t receiveBufSize=UDP_BUFFER_SIZE, bool nonBlocking=true)
 An easy constructor of an IPV4 or IPV6 SimpleUDP.
 
 SimpleUDP (const char *host, unsigned short port, size_t sendBufSize=UDP_BUFFER_SIZE, size_t receiveBufSize=UDP_BUFFER_SIZE, bool nonBlocking=true)
 An easy constructor of SimpleUDP based on host and port.
 
 
int Connect (const sockaddr *address, size_t addressLength)
 Connect underlying udp socket to server specified in address.
 
int ConnectToHost (const char *hostIP, unsigned short port) const
 An easy way to connect to host.
 
int ConnectToLocalHost (unsigned short port) const
 An easy way to connect to 127.0.0.1 or ::1 based on m_addressFamily.
 
int Bind (const sockaddr *address, size_t addressLength) const
 Bind underlying udp socket to an address.
 
int BindToLocalHost (unsigned short port) const
 An easy way to bind to localhost.
 
int SendData (const uint8_t *data, size_t dataLen) const
 Send data to server without specifying address, only usable if hostIP and port are available.
 
int SendDataTo (const sockaddr *address, size_t addressLength, const uint8_t *data, size_t dataLen) const
 Send data to server.
 
int SendDataToLocalHost (const uint8_t *data, size_t dataLen, unsigned short port) const
 An easy way to send data to localhost, when the underlying udp is connected, call this function will send the data to where it connects to, not essentially to localhost. when it's not connected, it will send data to localhost, but this call will not connect underlying socket to localhost for you.
 
int ReceiveData (uint8_t *buffer, size_t bufferLen) const
 Receive data from unique address specified in ConnectWithServer call. this function is equivalent to call ReceiveDataFrom(nullptr, 0, data, dataLen, flags).
 
int ReceiveDataFrom (sockaddr *address, size_t *addressLength, uint8_t *buffer, size_t bufferLen) const
 Receive data from network.
 
int GetAddressFamily () const
 
bool IsConnected () const
 

Detailed Description

SimpleUDP definition.

Definition at line 22 of file SimpleUDP.h.

Constructor & Destructor Documentation

◆ SimpleUDP() [1/3]

Aws::Net::SimpleUDP::SimpleUDP ( int  addressFamily,
size_t  sendBufSize = UDP_BUFFER_SIZE,
size_t  receiveBufSize = UDP_BUFFER_SIZE,
bool  nonBlocking = true 
)

Constructor of SimpleUDP.

Parameters
addressFamily,AF_INETfor IPV4 or AF_INET6 for IPV6
sendBufSize,ifnonzero, try set socket's send buffer size to this value.
receiveBufSize,ifnonzero, try set socket's receive buffer size to this value.
nonBlocking,ifit is true, implementation will try to create a non-blocking underlying UDP socket. Implementation should create and set the underlying udp socket.

◆ SimpleUDP() [2/3]

Aws::Net::SimpleUDP::SimpleUDP ( bool  IPV4 = true,
size_t  sendBufSize = UDP_BUFFER_SIZE,
size_t  receiveBufSize = UDP_BUFFER_SIZE,
bool  nonBlocking = true 
)

An easy constructor of an IPV4 or IPV6 SimpleUDP.

Parameters
addressFamily,eitherAF_INET for IPV4 or AF_INET6 for IPV6
sendBufSize,ifnonzero, try set socket's send buffer size to this value.
receiveBufSize,ifnonzero, try set socket's receive buffer size to this value.
nonBlocking,ifit is true, implementation will try to create a non-blocking underlying UDP socket. Implementation should create and set the underlying udp socket.

◆ SimpleUDP() [3/3]

Aws::Net::SimpleUDP::SimpleUDP ( const char *  host,
unsigned short  port,
size_t  sendBufSize = UDP_BUFFER_SIZE,
size_t  receiveBufSize = UDP_BUFFER_SIZE,
bool  nonBlocking = true 
)

An easy constructor of SimpleUDP based on host and port.

Parameters
host,thehost that packets will be sent to, could be ipv4 or ipv6 address, or a hostname Note that "localhost" is not necessarily bind to 127.0.0.1, it could bind to ipv6 address ::1, or other type of ip addresses. If you pass localhost here, we will go through getaddrinfo procedure on Linux and Windows.
port,theport number that the host listens on.
sendBufSize,ifnonzero, try set socket's send buffer size to this value.
receiveBufSize,ifnonzero, try set socket's receive buffer size to this value.
nonBlocking,ifit is true, implementation will try to create a non-blocking underlying UDP socket. Implementation should create and set the underlying udp socket.

◆ ~SimpleUDP()

Aws::Net::SimpleUDP::~SimpleUDP ( )

Member Function Documentation

◆ Bind()

int Aws::Net::SimpleUDP::Bind ( const sockaddr *  address,
size_t  addressLength 
) const

Bind underlying udp socket to an address.

Parameters
address,theserver's address info.
addressLength,lengthof address, structure of address can vary.
Returns
0 on success, -1 on error, check errno for detailed error information.

◆ BindToLocalHost()

int Aws::Net::SimpleUDP::BindToLocalHost ( unsigned short  port) const

An easy way to bind to localhost.

◆ Connect()

int Aws::Net::SimpleUDP::Connect ( const sockaddr *  address,
size_t  addressLength 
)

Connect underlying udp socket to server specified in address.

Parameters
address,theserver's address info.
addressLength,lengthof address, structure of address can vary.
Returns
0 on success, -1 on error, check errno for detailed error information.

◆ ConnectToHost()

int Aws::Net::SimpleUDP::ConnectToHost ( const char *  hostIP,
unsigned short  port 
) const

An easy way to connect to host.

Parameters
hostIP,avalid ipv4 or ipv6 address. The address type should match the m_addressFamily type settled during construction. Otherwise the connection will fail.
port,theport that host listens on.

◆ ConnectToLocalHost()

int Aws::Net::SimpleUDP::ConnectToLocalHost ( unsigned short  port) const

An easy way to connect to 127.0.0.1 or ::1 based on m_addressFamily.

◆ GetAddressFamily()

int Aws::Net::SimpleUDP::GetAddressFamily ( ) const
inline

Gets the AddressFamily used for the underlying socket. E.g. AF_INET, AF_INET6 etc.

Definition at line 144 of file SimpleUDP.h.

◆ IsConnected()

bool Aws::Net::SimpleUDP::IsConnected ( ) const
inline

Is the underlying socket connected with a remote address

Definition at line 149 of file SimpleUDP.h.

◆ ReceiveData()

int Aws::Net::SimpleUDP::ReceiveData ( uint8_t *  buffer,
size_t  bufferLen 
) const

Receive data from unique address specified in ConnectWithServer call. this function is equivalent to call ReceiveDataFrom(nullptr, 0, data, dataLen, flags).

Parameters
buffer,thememory address where you want to store received data.
bufferLen,thesize of data buffer.
Returns
-1 on failure, check errno for detailed error information, on success, returns the actual bytes of data received

◆ ReceiveDataFrom()

int Aws::Net::SimpleUDP::ReceiveDataFrom ( sockaddr *  address,
size_t *  addressLength,
uint8_t *  buffer,
size_t  bufferLen 
) const

Receive data from network.

Parameters
address,ifnot null and underlying implementation supply the incoming data's source address, this will be filled with source address info.
addressLength,thesize of source address, should not be null.
buffer,thememory address where you want to store received data.
bufferLen,thesize of data buffer.
Returns
-1 on failure, check errno for detailed error information, on success, returns the actual bytes of data received.

◆ SendData()

int Aws::Net::SimpleUDP::SendData ( const uint8_t *  data,
size_t  dataLen 
) const

Send data to server without specifying address, only usable if hostIP and port are available.

Parameters
data,thedata you want to send.
dataLen,thelength of data you want to send. On Windows, dataLen larger than INT32_MAX will cause undefined behavior
Returns
0 on success, -1 on error, check errno for detailed error information.

◆ SendDataTo()

int Aws::Net::SimpleUDP::SendDataTo ( const sockaddr *  address,
size_t  addressLength,
const uint8_t *  data,
size_t  dataLen 
) const

Send data to server.

Parameters
address,theserver's address info.
addressLength,lengthof address, structure of address can vary.
data,thememory address of the data you want to send.
dataLen,thelength of data you want to send. On Windows, dataLen larger than INT32_MAX will cause undefined behavior
Returns
0 on success, -1 on error check errno for detailed error information.

◆ SendDataToLocalHost()

int Aws::Net::SimpleUDP::SendDataToLocalHost ( const uint8_t *  data,
size_t  dataLen,
unsigned short  port 
) const

An easy way to send data to localhost, when the underlying udp is connected, call this function will send the data to where it connects to, not essentially to localhost. when it's not connected, it will send data to localhost, but this call will not connect underlying socket to localhost for you.

Parameters
data,thememory address of the data you want to send.
dataLen,thelength of data you want to send. On Windows, dataLen larger than INT32_MAX will cause undefined behavior
port,portof localhost.
Returns
0 on success, -1 on error, check errno for detailed error information.

The documentation for this class was generated from the following file: