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

connection layer for TCP connection management. More...

#include <TcpConnection.h>

Inherits AzNetworking::IConnection.

Public Member Functions

 TcpConnection (ConnectionId connectionId, const IpAddress &remoteAddress, TcpNetworkInterface &networkInterface, TcpSocket &socket)
 
 TcpConnection (ConnectionId connectionId, const IpAddress &remoteAddress, TcpNetworkInterface &networkInterface, TrustZone trustZone, bool useEncryption)
 
TcpSocketGetTcpSocket () const
 
bool IsOpen () const
 
bool Connect (uint16_t localPort)
 
void UpdateSend ()
 Handles any new outgoing network traffic.
 
bool UpdateRecv ()
 
bool SendReliablePacket (const IPacket &packet) override
 IConnection interface.
 
PacketId SendUnreliablePacket (const IPacket &packet) override
 
bool WasPacketAcked (PacketId packetId) const override
 
ConnectionState GetConnectionState () const override
 
ConnectionRole GetConnectionRole () const override
 
bool Disconnect (DisconnectReason reason, TerminationEndpoint endpoint) override
 
void SetConnectionMtu (uint32_t connectionMtu) override
 
uint32_t GetConnectionMtu () const override
 
void SetRegisteredSocketFd (SocketFd registeredSocketFd)
 
SocketFd GetRegisteredSocketFd () const
 
- Public Member Functions inherited from AzNetworking::IConnection
 IConnection (ConnectionId connectionId, const IpAddress &address)
 
ConnectionId GetConnectionId () const
 
void SetUserData (void *userData)
 
void * GetUserData () const
 
void SetRemoteAddress (const IpAddress &address)
 
const IpAddressGetRemoteAddress () const
 
const ConnectionMetricsGetMetrics () const
 
ConnectionMetricsGetMetrics ()
 
const ConnectionQualityGetConnectionQuality () const
 
ConnectionQualityGetConnectionQuality ()
 

Detailed Description

connection layer for TCP connection management.

Constructor & Destructor Documentation

◆ TcpConnection() [1/2]

AzNetworking::TcpConnection::TcpConnection ( ConnectionId  connectionId,
const IpAddress remoteAddress,
TcpNetworkInterface networkInterface,
TcpSocket socket 
)

Construct with an existing socket, used when accepting an incoming connection

Parameters
connectionIdconnection identifier of this connection instance
remoteAddressIP address of the remote endpoint
networkInterfaceTcpNetworkInterface that owns this connection instance
socketTCP socket to take ownership of and use for sending and receiving data

◆ TcpConnection() [2/2]

AzNetworking::TcpConnection::TcpConnection ( ConnectionId  connectionId,
const IpAddress remoteAddress,
TcpNetworkInterface networkInterface,
TrustZone  trustZone,
bool  useEncryption 
)

Construct a new socket with optional encryption, used when initiating a new connection

Parameters
connectionIdconnection identifier of this connection instance
remoteAddressIP address of the remote endpoint
networkInterfaceTcpNetworkInterface that owns this connection instance
trustZonefor encrypted connections, the level of trust we associate with this connection (internal or external)
useEncryptionif true connections will be made over TLS

Member Function Documentation

◆ Connect()

bool AzNetworking::TcpConnection::Connect ( uint16_t  localPort)

Connects to the provided remote address.

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

◆ Disconnect()

bool AzNetworking::TcpConnection::Disconnect ( DisconnectReason  reason,
TerminationEndpoint  endpoint 
)
overridevirtual

Disconnects the connection with the provided termination reason

Parameters
reasonreason for the disconnect
endpointwhich endpoint initiated the disconnect, local or remote
Returns
boolean true on success

Implements AzNetworking::IConnection.

◆ GetConnectionMtu()

uint32_t AzNetworking::TcpConnection::GetConnectionMtu ( ) const
overridevirtual

Returns the connection maximum transmission unit. Currently unsupported on TcpConnections

Returns
the max transmission unit for this connection

Implements AzNetworking::IConnection.

◆ GetConnectionRole()

ConnectionRole AzNetworking::TcpConnection::GetConnectionRole ( ) const
overridevirtual

Retrieves the connection role of this connection instance, whether it was initiated or accepted.

Returns
whether this connection was initiated or accepted

Implements AzNetworking::IConnection.

◆ GetConnectionState()

ConnectionState AzNetworking::TcpConnection::GetConnectionState ( ) const
overridevirtual

Retrieves the connection state for this IConnection instance.

Returns
the current connection state for this IConnection instance

Implements AzNetworking::IConnection.

◆ GetRegisteredSocketFd()

SocketFd AzNetworking::TcpConnection::GetRegisteredSocketFd ( ) const
inline

Returns the socket file descriptor for this TcpConnection in the associated ConnectionSet instance.

Returns
the socket file descriptor for this TcpConnection in the associated ConnectionSet instance

◆ GetTcpSocket()

TcpSocket * AzNetworking::TcpConnection::GetTcpSocket ( ) const
inline

Returns the TcpSocket bound to this TcpConnection.

Returns
the TcpSocket bound to this TcpConnection

◆ IsOpen()

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

Returns true if this connection instance is in an open state, and is capable of actively sending and receiving packets.

Returns
boolean true if this connection instance is in an open state

◆ SendUnreliablePacket()

PacketId AzNetworking::TcpConnection::SendUnreliablePacket ( const IPacket packet)
overridevirtual

A helper function that transmits a packet on this connection unreliably.

Parameters
packetpacket to transmit
Returns
the unreliable packet identifier of the transmitted packet

Implements AzNetworking::IConnection.

◆ SetConnectionMtu()

void AzNetworking::TcpConnection::SetConnectionMtu ( uint32_t  connectionMtu)
overridevirtual

Sets connection maximum transmission unit for this connection. Currently unsupported on TcpConnections

Parameters
connectionMtuthe max transmission unit for this connection

Implements AzNetworking::IConnection.

◆ SetRegisteredSocketFd()

void AzNetworking::TcpConnection::SetRegisteredSocketFd ( SocketFd  registeredSocketFd)
inline

Sets the registered socket file descriptor for this TcpConnection in the associated ConnectionSet instance.

Parameters
registeredSocketFdthe socket file descriptor for this TcpConnection in the associated ConnectionSet instance

◆ UpdateRecv()

bool AzNetworking::TcpConnection::UpdateRecv ( )

Handles any new incoming network traffic.

Returns
boolean true if the socket is still active, false if it has been remotely terminated

◆ WasPacketAcked()

bool AzNetworking::TcpConnection::WasPacketAcked ( PacketId  packetId) const
overridevirtual

Returns true if the given packet id was confirmed acknowledged by the remote endpoint, false otherwise.

Parameters
packetIdthe packet id of the packet to confirm acknowledgment of
Returns
boolean true if the packet is confirmed acknowledged, false if the packet number is out of range, lost, or still pending acknowledgment

Implements AzNetworking::IConnection.


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