Open 3D Engine AzFramework 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.
AzFramework::SocketConnection Class Referenceabstract

#include <SocketConnection.h>

Inherited by AzFramework::AssetSystem::AssetProcessorConnection.

Public Types

enum class  EConnectionState {
  Connected , Connecting , Disconnected , Disconnecting ,
  Listening
}
 
typedef AZStd::function< void(AZ::u32, AZ::u32, const void *, AZ::u32)> TMessageCallback
 
typedef AZ::u32 TMessageCallbackHandle
 

Public Member Functions

 AZ_RTTI (SocketConnection, "{CF95282C-B514-4AB8-8C72-6063AD03725B}")
 
virtual bool Connect (const char *address, AZ::u16 port)=0
 
virtual bool Disconnect (bool completeDisconnect=false)=0
 
virtual bool Listen (AZ::u16 port)=0
 
virtual EConnectionState GetConnectionState () const =0
 Get the current connection state.
 
virtual bool IsConnected () const =0
 
virtual bool IsDisconnected () const =0
 
virtual bool SendMsg (AZ::u32 typeId, const void *dataBuffer, AZ::u32 dataLength)=0
 Send a message across the connection by message id.
 
virtual bool SendMsg (AZ::u32 typeId, AZ::u32 serial, const void *dataBuffer, AZ::u32 dataLength)=0
 Send a message across the connection by message id.
 
virtual bool SendRequest (AZ::u32 typeId, const void *dataBuffer, AZ::u32 dataLength, TMessageCallback handler)=0
 Send a message and wait for the response.
 
virtual TMessageCallbackHandle AddMessageHandler (AZ::u32 typeId, TMessageCallback callback)=0
 
virtual void RemoveMessageHandler (AZ::u32 typeId, TMessageCallbackHandle callbackHandle)=0
 Remove callback for specific typeId (allows multiple callbacks per id)
 
virtual AZ::s32 GetLastResult () const
 Get the last socket result code from any socket call.
 
virtual AZStd::string GetLastErrorMessage () const
 Get the last socket-related error from any socket call.
 

Static Public Member Functions

static SocketConnectionGetInstance ()
 Utility functions to get or set the one global instance of a SocketConnection.
 
static void SetInstance (SocketConnection *instance)
 

Static Public Attributes

static const TMessageCallbackHandle s_invalidCallbackHandle = 0
 

Detailed Description

SocketConnection - an interface for creating a socket connection using AzSocket

Member Typedef Documentation

◆ TMessageCallback

typedef AZStd::function<void(AZ::u32, AZ::u32, const void*, AZ::u32)> AzFramework::SocketConnection::TMessageCallback

Callback parameters: Message ID, Serial, Data Buffer, Data Length Note that if the message is a request and it failed because of a protocol error (engine is shutting down for example) It is still guaranteed to be called, but will be called with 0, nullptr

Member Function Documentation

◆ AddMessageHandler()

virtual TMessageCallbackHandle AzFramework::SocketConnection::AddMessageHandler ( AZ::u32  typeId,
TMessageCallback  callback 
)
pure virtual

Add callback for specific typeId (allows multiple callbacks per id) This will be invoked when a complete message is received from the remote end

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ Connect()

virtual bool AzFramework::SocketConnection::Connect ( const char *  address,
AZ::u16  port 
)
pure virtual

Connect to an address with this connection. Takes a null-terminated string address and a port Currently this blocks until connected

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ Disconnect()

virtual bool AzFramework::SocketConnection::Disconnect ( bool  completeDisconnect = false)
pure virtual

Disconnect from connection - Only works if actually connected completeDisconnect - True if this function should wait for the connection to be fully terminated before returning. False for async behavior.

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ GetConnectionState()

virtual EConnectionState AzFramework::SocketConnection::GetConnectionState ( ) const
pure virtual

Get the current connection state.

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ GetLastErrorMessage()

virtual AZStd::string AzFramework::SocketConnection::GetLastErrorMessage ( ) const
inlinevirtual

Get the last socket-related error from any socket call.

Reimplemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ GetLastResult()

virtual AZ::s32 AzFramework::SocketConnection::GetLastResult ( ) const
inlinevirtual

Get the last socket result code from any socket call.

Reimplemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ Listen()

virtual bool AzFramework::SocketConnection::Listen ( AZ::u16  port)
pure virtual

Listen for one connection on a port This does not block and will set state to listening until connected

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ RemoveMessageHandler()

virtual void AzFramework::SocketConnection::RemoveMessageHandler ( AZ::u32  typeId,
TMessageCallbackHandle  callbackHandle 
)
pure virtual

Remove callback for specific typeId (allows multiple callbacks per id)

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ SendMsg() [1/2]

virtual bool AzFramework::SocketConnection::SendMsg ( AZ::u32  typeId,
AZ::u32  serial,
const void *  dataBuffer,
AZ::u32  dataLength 
)
pure virtual

Send a message across the connection by message id.

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ SendMsg() [2/2]

virtual bool AzFramework::SocketConnection::SendMsg ( AZ::u32  typeId,
const void *  dataBuffer,
AZ::u32  dataLength 
)
pure virtual

Send a message across the connection by message id.

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.

◆ SendRequest()

virtual bool AzFramework::SocketConnection::SendRequest ( AZ::u32  typeId,
const void *  dataBuffer,
AZ::u32  dataLength,
TMessageCallback  handler 
)
pure virtual

Send a message and wait for the response.

Implemented in AzFramework::AssetSystem::AssetProcessorConnection.


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