The Socket class provides TCP or UDP ethernet networking.
More...
#include <Socket.h>
|
| ~Socket () |
| Destructor. More...
|
|
bool | Accept (uint64_t timeout=0) |
| Accept incoming connections (TCP only). More...
|
|
bool | Bind (const char *localIP, uint16_t port) |
| Bind the socket to a local host IP address and port. More...
|
|
bool | Bind (uint32_t localIP, uint16_t port) |
| Bind the socket to a local host IP address and port. More...
|
|
bool | Bind (uint16_t port=0) |
| Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY). More...
|
|
bool | Connect (const char *remoteIP, uint16_t port) |
| Connect to a listening server (TCP only). More...
|
|
bool | Connect (uint32_t remoteIP, uint16_t port) |
| Connect to a listening server (TCP only). More...
|
|
size_t | Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP=NULL, uint16_t *remotePort=NULL) |
| Wait for a packet to be recieved and dump it into the user-supplied buffer. More...
|
|
size_t | Recieve (uint8_t *buffer, size_t size, uint32_t *remoteIP, uint16_t *remotePort, uint32_t *localIP) |
| Recieve packet, with additional address info. More...
|
|
bool | Send (void *buffer, size_t size, uint32_t remoteIP, uint16_t remotePort) |
| Send message to remote host. More...
|
|
bool | SetRecieveTimeout (uint64_t timeout) |
| Set Receive() timeout (in microseconds). More...
|
|
bool | SetBufferSize (size_t size) |
| Set the rx/tx buffer sizes. More...
|
|
bool | EnableJumboBuffer () |
| Enable jumbo buffer. More...
|
|
int | GetFD () const |
| Retrieve the socket's file descriptor. More...
|
|
SocketType | GetType () const |
| GetType. More...
|
|
void | PrintIP () const |
| PrintIP. More...
|
|
size_t | GetMTU () |
| Retrieve the MTU (in bytes). More...
|
|
The Socket class provides TCP or UDP ethernet networking.
To exchange data with a remote IP on the network using UDP, follow these steps:
1. Create a Socket instance with the static Create() function.
- Bind() the Socket to a host IP address and port
- Exchange data with the Send/Recv functions
◆ ~Socket()
◆ Accept()
bool Socket::Accept |
( |
uint64_t |
timeout = 0 | ) |
|
Accept incoming connections (TCP only).
- Parameters
-
timeout | The timeout (in microseconds) to wait for incoming connections before returning. |
◆ Bind() [1/3]
bool Socket::Bind |
( |
const char * |
localIP, |
|
|
uint16_t |
port |
|
) |
| |
Bind the socket to a local host IP address and port.
- Parameters
-
ipAddress | IPv4 address in string format "xxx.xxx.xxx.xxx" |
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
◆ Bind() [2/3]
bool Socket::Bind |
( |
uint32_t |
localIP, |
|
|
uint16_t |
port |
|
) |
| |
Bind the socket to a local host IP address and port.
- Parameters
-
hostIP | IPv4 address, in network byte order. If htonl(INADDR_ANY) is specified for the ipAddress, the socket will be bound to all available interfaces. |
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
◆ Bind() [3/3]
bool Socket::Bind |
( |
uint16_t |
port = 0 | ) |
|
Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY).
- Parameters
-
port | the port number (0-65536), in host byte order. If the port specified is 0, the socket will be bound to any available port. |
◆ Connect() [1/2]
bool Socket::Connect |
( |
const char * |
remoteIP, |
|
|
uint16_t |
port |
|
) |
| |
Connect to a listening server (TCP only).
- Parameters
-
remoteIP | IP address of the remote host. |
◆ Connect() [2/2]
bool Socket::Connect |
( |
uint32_t |
remoteIP, |
|
|
uint16_t |
port |
|
) |
| |
Connect to a listening server (TCP only).
- Parameters
-
remoteIP | IP address of the remote host. |
◆ Create()
◆ EnableJumboBuffer()
bool Socket::EnableJumboBuffer |
( |
| ) |
|
◆ GetFD()
int Socket::GetFD |
( |
| ) |
const |
|
inline |
Retrieve the socket's file descriptor.
◆ GetMTU()
size_t Socket::GetMTU |
( |
| ) |
|
Retrieve the MTU (in bytes).
Returns 0 on error.
◆ GetType()
◆ PrintIP()
void Socket::PrintIP |
( |
| ) |
const |
◆ Recieve() [1/2]
size_t Socket::Recieve |
( |
uint8_t * |
buffer, |
|
|
size_t |
size, |
|
|
uint32_t * |
remoteIP = NULL , |
|
|
uint16_t * |
remotePort = NULL |
|
) |
| |
Wait for a packet to be recieved and dump it into the user-supplied buffer.
Optionally return the IP address and port of the remote host which sent the packet.
- Parameters
-
buffer | user-allocated destination for the packet |
size | size of the buffer (in bytes) |
remoteIpAddress | optional output, the IPv4 address of where the packet originated (in network byte order). |
remotePort | optional output, the port from where the packet originated (in host byte order). |
- Returns
- the size (in bytes) of the packet sucessfully written to buffer.
◆ Recieve() [2/2]
size_t Socket::Recieve |
( |
uint8_t * |
buffer, |
|
|
size_t |
size, |
|
|
uint32_t * |
remoteIP, |
|
|
uint16_t * |
remotePort, |
|
|
uint32_t * |
localIP |
|
) |
| |
Recieve packet, with additional address info.
In addition to returning the IP and port of the remote host which sent the packet, this function can also return the local IP and port which the packet was sent to.
- See also
- Recieve()
◆ Send()
bool Socket::Send |
( |
void * |
buffer, |
|
|
size_t |
size, |
|
|
uint32_t |
remoteIP, |
|
|
uint16_t |
remotePort |
|
) |
| |
Send message to remote host.
◆ SetBufferSize()
bool Socket::SetBufferSize |
( |
size_t |
size | ) |
|
Set the rx/tx buffer sizes.
◆ SetRecieveTimeout()
bool Socket::SetRecieveTimeout |
( |
uint64_t |
timeout | ) |
|
Set Receive() timeout (in microseconds).
The documentation for this class was generated from the following file: