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::TcpNetworkInterface Class Referencefinal

This class implements a TCP network interface. More...

#include <TcpNetworkInterface.h>

Inherits AzNetworking::INetworkInterface.

Classes

struct  PendingConnection
 helper structure for transferring new pending connections from the listen thread to network interface. More...
 

Public Member Functions

 TcpNetworkInterface (const AZ::Name &name, IConnectionListener &connectionListener, TrustZone trustZone, TcpListenThread &listenThread)
 
void QueueNewConnection (const PendingConnection &pendingConnection)
 
AZ::Name GetName () const override
 
ProtocolType GetType () const override
 
TrustZone GetTrustZone () const override
 
uint16_t GetPort () const override
 
IConnectionSetGetConnectionSet () override
 
IConnectionListenerGetConnectionListener () override
 
bool Listen (uint16_t port) override
 
ConnectionId Connect (const IpAddress &remoteAddress, uint16_t localPort=0) override
 
void Update () override
 Updates the INetworkInterface.
 
bool SendReliablePacket (ConnectionId connectionId, const IPacket &packet) override
 
PacketId SendUnreliablePacket (ConnectionId connectionId, const IPacket &packet) override
 
bool WasPacketAcked (ConnectionId connectionId, PacketId packetId) override
 
bool StopListening () override
 
bool Disconnect (ConnectionId connectionId, DisconnectReason reason) override
 
void SetTimeoutMs (AZ::TimeMs timeoutMs) override
 
AZ::TimeMs GetTimeoutMs () const override
 
bool IsEncrypted () const override
 
bool IsOpen () const override
 
- Public Member Functions inherited from AzNetworking::INetworkInterface
 AZ_RTTI (INetworkInterface, "{ECDA6FA2-4AA0-435E-881F-214C4B179A31}")
 
virtual AZ::Name GetName () const =0
 
virtual ProtocolType GetType () const =0
 
virtual TrustZone GetTrustZone () const =0
 
virtual uint16_t GetPort () const =0
 
virtual IConnectionSetGetConnectionSet ()=0
 
virtual IConnectionListenerGetConnectionListener ()=0
 
virtual bool Listen (uint16_t port)=0
 
virtual ConnectionId Connect (const IpAddress &remoteAddress, uint16_t localPort=0)=0
 
virtual void Update ()=0
 Updates the INetworkInterface.
 
virtual bool SendReliablePacket (ConnectionId connectionId, const IPacket &packet)=0
 
virtual PacketId SendUnreliablePacket (ConnectionId connectionId, const IPacket &packet)=0
 
virtual bool WasPacketAcked (ConnectionId connectionId, PacketId packetId)=0
 
virtual bool StopListening ()=0
 
virtual bool Disconnect (ConnectionId connectionId, DisconnectReason reason)=0
 
virtual void SetTimeoutMs (AZ::TimeMs timeoutMs)=0
 
virtual AZ::TimeMs GetTimeoutMs () const =0
 
const NetworkInterfaceMetricsGetMetrics () const
 
NetworkInterfaceMetricsGetMetrics ()
 
virtual bool IsEncrypted () const =0
 
virtual bool IsOpen () const =0
 

Friends

class TcpConnection
 

Detailed Description

This class implements a TCP network interface.

TcpNetworkInterface is an implementation of AzNetworking::INetworkInterface. Unlike UDP, TCP implements a variety of transport features such as congestion avoidance, flow control, and reliability. These features are valuable, but TCP offers minimal configuration of them. This is why UdpNetworkInterface offers similar features, but with greater flexibility in configuration. If your project doesn't require the low latency of UDP, consider using TCP.

Packet structure

  • Flags - A bitfield a receiving endpoint can quickly inspect to learn about configuration of a packet
  • Header - Details the type of packet and other information related to reliability
  • Payload - The actual serialized content of the packet

For more information, read Networking Packets in the O3DE documentation.

Reliability

TCP packets can only be sent reliably. This is a feature of TCP itself.

Fragmentation

TCP implements fragmentation under the hood. Consumers of TCP packets will never need to worry about reconstructing the contents over multiple transmissions.

Compression

Compression here refers to content insensitive compression using libraries like LZ4. If enabled, the target payload is run through the compressor and replaces the original payload if it's in fact smaller. To tell if compression is enabled on a given packet, we operate on a bit in the packet's Flags. The Sender writes this bit while the Receiver checks it to see if a packet needs to be decompressed.

Encryption

AzNetworking uses the OpenSSL library to implement TLS encryption. If enabled, the O3DE network layer handles the OpenSSL handshake under the hood using provided certificates.

Constructor & Destructor Documentation

◆ TcpNetworkInterface()

AzNetworking::TcpNetworkInterface::TcpNetworkInterface ( const AZ::Name &  name,
IConnectionListener connectionListener,
TrustZone  trustZone,
TcpListenThread listenThread 
)

Constructor.

Parameters
namethe name of this network interface instance.
connectionListenerreference to the connection listener responsible for handling all connection events
trustZonethe trust level assigned to this network interface, server to server or client to server
listenThreadthe listen thread to bind to this network interface

Member Function Documentation

◆ Connect()

ConnectionId AzNetworking::TcpNetworkInterface::Connect ( const IpAddress remoteAddress,
uint16_t  localPort = 0 
)
overridevirtual

Opens a new connection to the provided address.

Parameters
remoteAddressthe IpAddress of the remote process to open a connection to
localPortthe local port number to open a socket on to initiate the connection, 0 binds to any available port
Returns
the connectionId of the new connection, or InvalidConnectionId if the operation failed

Implements AzNetworking::INetworkInterface.

◆ Disconnect()

bool AzNetworking::TcpNetworkInterface::Disconnect ( ConnectionId  connectionId,
DisconnectReason  reason 
)
overridevirtual

Disconnects the specified connection.

Parameters
connectionIdidentifier of the connection to terminate
reasonreason for the disconnect
Returns
boolean true on success

Implements AzNetworking::INetworkInterface.

◆ GetConnectionListener()

IConnectionListener & AzNetworking::TcpNetworkInterface::GetConnectionListener ( )
overridevirtual

Returns a reference to the connection listener for this network interface.

Returns
reference to the connection listener for this network interface

Implements AzNetworking::INetworkInterface.

◆ GetConnectionSet()

IConnectionSet & AzNetworking::TcpNetworkInterface::GetConnectionSet ( )
overridevirtual

Returns the connection set for this network interface.

Returns
the connection set for this network interface

Implements AzNetworking::INetworkInterface.

◆ GetName()

AZ::Name AzNetworking::TcpNetworkInterface::GetName ( ) const
overridevirtual

◆ GetPort()

uint16_t AzNetworking::TcpNetworkInterface::GetPort ( ) const
overridevirtual

Returns the port number this network interface is bound to.

Returns
the port number this network interface is bound to

Implements AzNetworking::INetworkInterface.

◆ GetTimeoutMs()

AZ::TimeMs AzNetworking::TcpNetworkInterface::GetTimeoutMs ( ) const
overridevirtual

Retrieves the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled.

Returns
the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled

Implements AzNetworking::INetworkInterface.

◆ GetTrustZone()

TrustZone AzNetworking::TcpNetworkInterface::GetTrustZone ( ) const
overridevirtual

Retrieves the trust zone for this network interface instance.

Returns
the trust zone for this network interface instance

Implements AzNetworking::INetworkInterface.

◆ GetType()

ProtocolType AzNetworking::TcpNetworkInterface::GetType ( ) const
overridevirtual

Retrieves the type of this network interface instance.

Returns
the type of this network interface instance

Implements AzNetworking::INetworkInterface.

◆ IsEncrypted()

bool AzNetworking::TcpNetworkInterface::IsEncrypted ( ) const
overridevirtual

Returns true if communications on this network interface are encrypted, false if not.

Returns
boolean true if communciations are encrypted, false if not

Implements AzNetworking::INetworkInterface.

◆ IsOpen()

bool AzNetworking::TcpNetworkInterface::IsOpen ( ) const
overridevirtual

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

Implements AzNetworking::INetworkInterface.

◆ Listen()

bool AzNetworking::TcpNetworkInterface::Listen ( uint16_t  port)
overridevirtual

Opens the network interface to allow it to accept new incoming connections.

Parameters
portthe listen port number this network interface will potentially bind to, 0 if it's a don't care
Returns
boolean true if the operation was successful, false if it failed

Implements AzNetworking::INetworkInterface.

◆ QueueNewConnection()

void AzNetworking::TcpNetworkInterface::QueueNewConnection ( const PendingConnection pendingConnection)

Queues a new incoming connection for this network interface.

Parameters
pendingConnectioninfo on the new incoming connection

◆ SendReliablePacket()

bool AzNetworking::TcpNetworkInterface::SendReliablePacket ( ConnectionId  connectionId,
const IPacket packet 
)
overridevirtual

A helper function that transmits a packet on this connection reliably. Note that a packetId is not returned here, since retransmits may cause the packetId to change

Parameters
connectionIdidentifier of the connection to send to
packetpacket to transmit
Returns
boolean true if the packet was transmitted (not an indication of delivery)

Implements AzNetworking::INetworkInterface.

◆ SendUnreliablePacket()

PacketId AzNetworking::TcpNetworkInterface::SendUnreliablePacket ( ConnectionId  connectionId,
const IPacket packet 
)
overridevirtual

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

Parameters
connectionIdidentifier of the connection to send to
packetpacket to transmit
Returns
the unreliable packet identifier of the transmitted packet

Implements AzNetworking::INetworkInterface.

◆ SetTimeoutMs()

void AzNetworking::TcpNetworkInterface::SetTimeoutMs ( AZ::TimeMs  timeoutMs)
overridevirtual

Sets the timeout time in milliseconds, 0 ms means timeouts are disabled.

Parameters
timeoutMsthe number of milliseconds with no traffic before we timeout and close a connection

Implements AzNetworking::INetworkInterface.

◆ StopListening()

bool AzNetworking::TcpNetworkInterface::StopListening ( )
overridevirtual

Closes the network interface to stop accepting new incoming connections.

Returns
boolean true if the operation was successful, false if it failed

Implements AzNetworking::INetworkInterface.

◆ Update()

void AzNetworking::TcpNetworkInterface::Update ( )
overridevirtual

◆ WasPacketAcked()

bool AzNetworking::TcpNetworkInterface::WasPacketAcked ( ConnectionId  connectionId,
PacketId  packetId 
)
overridevirtual

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

Parameters
connectionIdidentifier of the connection to send to
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::INetworkInterface.


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