Open 3D Engine AzNetworking API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AzNetworking::TcpSocket Class Reference

wrapper class for managing TCP sockets. More...

#include <TcpSocket.h>

Inherited by AzNetworking::TlsSocket.

Public Member Functions

 TcpSocket (SocketFd socketFd)
 
virtual TcpSocketCloneAndTakeOwnership ()
 
virtual bool IsEncrypted () const
 
virtual bool Listen (uint16_t port)
 
virtual bool Connect (const IpAddress &address, uint16_t localPort)
 
virtual void Close ()
 Closes an open socket.
 
bool IsOpen () const
 
void SetSocketFd (SocketFd socketFd)
 
SocketFd GetSocketFd () const
 
int32_t Send (const uint8_t *data, uint32_t size) const
 
int32_t Receive (uint8_t *outData, uint32_t size) const
 

Protected Attributes

SocketFd m_socketFd
 

Detailed Description

wrapper class for managing TCP sockets.

Constructor & Destructor Documentation

◆ TcpSocket()

AzNetworking::TcpSocket::TcpSocket ( SocketFd  socketFd)

Construct with an existing socket file descriptor.

Parameters
socketFdexisting socket file descriptor, this TcpSocket instance will assume ownership

Member Function Documentation

◆ CloneAndTakeOwnership()

virtual TcpSocket * AzNetworking::TcpSocket::CloneAndTakeOwnership ( )
virtual

Creates a new socket instance, transferring all ownership from the current instance to the new instance.

Returns
new socket instance

Reimplemented in AzNetworking::TlsSocket.

◆ Close()

virtual void AzNetworking::TcpSocket::Close ( )
virtual

Closes an open socket.

Reimplemented in AzNetworking::TlsSocket.

◆ Connect()

virtual bool AzNetworking::TcpSocket::Connect ( const IpAddress address,
uint16_t  localPort 
)
virtual

Opens the TCP socket and connects to the requested remote address.

Parameters
addressthe remote endpoint to connect to
localPortthe local port to open a connection from, 0 binds to any available port
Returns
boolean true on success

Reimplemented in AzNetworking::TlsSocket.

◆ GetSocketFd()

SocketFd AzNetworking::TcpSocket::GetSocketFd ( ) const
inline

Returns the underlying socket file descriptor.

Returns
the underlying socket file descriptor

◆ IsEncrypted()

virtual bool AzNetworking::TcpSocket::IsEncrypted ( ) const
virtual

Returns true if this is an encrypted socket, false if not.

Returns
boolean true if this is an encrypted socket, false if not

Reimplemented in AzNetworking::TlsSocket.

◆ IsOpen()

bool AzNetworking::TcpSocket::IsOpen ( ) const
inline

Returns true if the socket is currently in an open state.

Returns
boolean true if the socket is in a connected state

◆ Listen()

virtual bool AzNetworking::TcpSocket::Listen ( uint16_t  port)
virtual

Opens the TCP socket and binds it in listen mode.

Parameters
portthe port number to open the TCP socket and begin listening on, 0 will bind to any available port
Returns
boolean true on success

Reimplemented in AzNetworking::TlsSocket.

◆ Receive()

int32_t AzNetworking::TcpSocket::Receive ( uint8_t *  outData,
uint32_t  size 
) const

Receives a payload from the TCP socket.

Parameters
outAddresson success, the address of the endpoint that sent the data
outDataon success, address to write the received data to
sizemaximum size the output buffer supports for receiving
Returns
number of bytes received, <= 0 on error

◆ Send()

int32_t AzNetworking::TcpSocket::Send ( const uint8_t *  data,
uint32_t  size 
) const

Sends a chunk of data to the connected endpoint.

Parameters
addressthe address to send the payload to
datapointer to the data to send
sizesize of the payload in bytes
Returns
number of bytes sent, <= 0 on error

◆ SetSocketFd()

void AzNetworking::TcpSocket::SetSocketFd ( SocketFd  socketFd)
inline

Sets the underlying socket file descriptor.

Parameters
socketFdthe new underlying socket file descriptor to use for this TcpSocket instance

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