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 |
IConnectionSet & | GetConnectionSet () override |
IConnectionListener & | GetConnectionListener () 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 IConnectionSet & | GetConnectionSet ()=0 |
virtual IConnectionListener & | GetConnectionListener ()=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 NetworkInterfaceMetrics & | GetMetrics () const |
NetworkInterfaceMetrics & | GetMetrics () |
virtual bool | IsEncrypted () const =0 |
virtual bool | IsOpen () const =0 |
Friends | |
class | TcpConnection |
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.
For more information, read Networking Packets in the O3DE documentation.
TCP packets can only be sent reliably. This is a feature of TCP itself.
TCP implements fragmentation under the hood. Consumers of TCP packets will never need to worry about reconstructing the contents over multiple transmissions.
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.
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.
AzNetworking::TcpNetworkInterface::TcpNetworkInterface | ( | const AZ::Name & | name, |
IConnectionListener & | connectionListener, | ||
TrustZone | trustZone, | ||
TcpListenThread & | listenThread | ||
) |
Constructor.
name | the name of this network interface instance. |
connectionListener | reference to the connection listener responsible for handling all connection events |
trustZone | the trust level assigned to this network interface, server to server or client to server |
listenThread | the listen thread to bind to this network interface |
|
overridevirtual |
Opens a new connection to the provided address.
remoteAddress | the IpAddress of the remote process to open a connection to |
localPort | the local port number to open a socket on to initiate the connection, 0 binds to any available port |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Disconnects the specified connection.
connectionId | identifier of the connection to terminate |
reason | reason for the disconnect |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns a reference to the connection listener for this network interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns the connection set for this network interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
INetworkInterface interface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns the port number this network interface is bound to.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the timeout time in milliseconds for this network interface, 0 ms means timeouts are disabled.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the trust zone for this network interface instance.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Retrieves the type of this network interface instance.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if communications on this network interface are encrypted, false if not.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if this connection instance is in an open state, and is capable of actively sending and receiving packets.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Opens the network interface to allow it to accept new incoming connections.
port | the listen port number this network interface will potentially bind to, 0 if it's a don't care |
Implements AzNetworking::INetworkInterface.
void AzNetworking::TcpNetworkInterface::QueueNewConnection | ( | const PendingConnection & | pendingConnection | ) |
Queues a new incoming connection for this network interface.
pendingConnection | info on the new incoming connection |
|
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
connectionId | identifier of the connection to send to |
packet | packet to transmit |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
A helper function that transmits a packet on this connection unreliably.
connectionId | identifier of the connection to send to |
packet | packet to transmit |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Sets the timeout time in milliseconds, 0 ms means timeouts are disabled.
timeoutMs | the number of milliseconds with no traffic before we timeout and close a connection |
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Closes the network interface to stop accepting new incoming connections.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Updates the INetworkInterface.
Implements AzNetworking::INetworkInterface.
|
overridevirtual |
Returns true if the given packet id was confirmed acknowledged by the remote endpoint, false otherwise.
connectionId | identifier of the connection to send to |
packetId | the packet id of the packet to confirm acknowledgment of |
Implements AzNetworking::INetworkInterface.