Jetson Inference
DNN Vision Library

The Socket class provides TCP or UDP ethernet networking. More...

#include <Socket.h>

Public Member Functions

 ~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...
 

Static Public Member Functions

static SocketCreate (SocketType type)
 Create. More...
 

Detailed Description

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.
  1. Bind() the Socket to a host IP address and port
  2. Exchange data with the Send/Recv functions

Constructor & Destructor Documentation

◆ ~Socket()

Socket::~Socket ( )

Destructor.

Member Function Documentation

◆ Accept()

bool Socket::Accept ( uint64_t  timeout = 0)

Accept incoming connections (TCP only).

Parameters
timeoutThe 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
ipAddressIPv4 address in string format "xxx.xxx.xxx.xxx"
portthe 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 ( uint16_t  port = 0)

Bind the socket to a local host port, on any interface (0.0.0.0 INADDR_ANY).

Parameters
portthe 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 ( uint32_t  localIP,
uint16_t  port 
)

Bind the socket to a local host IP address and port.

Parameters
hostIPIPv4 address, in network byte order. If htonl(INADDR_ANY) is specified for the ipAddress, the socket will be bound to all available interfaces.
portthe 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
remoteIPIP 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
remoteIPIP address of the remote host.

◆ Create()

static Socket* Socket::Create ( SocketType  type)
static

Create.

◆ EnableJumboBuffer()

bool Socket::EnableJumboBuffer ( )

Enable jumbo buffer.

◆ 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()

SocketType Socket::GetType ( ) const
inline

GetType.

◆ PrintIP()

void Socket::PrintIP ( ) const

PrintIP.

◆ Recieve() [1/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()

◆ Recieve() [2/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
bufferuser-allocated destination for the packet
sizesize of the buffer (in bytes)
remoteIpAddressoptional output, the IPv4 address of where the packet originated (in network byte order).
remotePortoptional output, the port from where the packet originated (in host byte order).
Returns
the size (in bytes) of the packet sucessfully written to buffer.

◆ 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: