UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ISocketSubsystem Class Referenceabstract

#include <SocketSubsystem.h>

Public Member Functions

SOCKETS_API ISocketSubsystem ()
 
virtual SOCKETS_API ~ISocketSubsystem ()
 
virtual bool Init (FString &Error)=0
 
virtual void Shutdown ()=0
 
virtual FSocketCreateSocket (const FName &SocketType, const FString &SocketDescription, bool bForceUDP=false)
 
virtual FSocketCreateSocket (const FName &SocketType, const FString &SocketDescription, ESocketProtocolFamily ProtocolType)
 
virtual FSocketCreateSocket (const FName &SocketType, const FString &SocketDescription, const FName &ProtocolName)=0
 
SOCKETS_API FUniqueSocket CreateUniqueSocket (const FName &SocketType, const FString &SocketDescription, bool bForceUDP=false)
 
SOCKETS_API FUniqueSocket CreateUniqueSocket (const FName &SocketType, const FString &SocketDescription, const FName &ProtocolName)
 
virtual SOCKETS_API class FResolveInfoCachedCreateResolveInfoCached (TSharedPtr< FInternetAddr > Addr) const
 
virtual void DestroySocket (FSocket *Socket)=0
 
virtual FAddressInfoResult GetAddressInfo (const TCHAR *HostName, const TCHAR *ServiceName=nullptr, EAddressInfoFlags QueryFlags=EAddressInfoFlags::Default, ESocketProtocolFamily ProtocolType=ESocketProtocolFamily::None, ESocketType SocketType=ESocketType::SOCKTYPE_Unknown)
 
virtual FAddressInfoResult GetAddressInfo (const TCHAR *HostName, const TCHAR *ServiceName=nullptr, EAddressInfoFlags QueryFlags=EAddressInfoFlags::Default, const FName ProtocolTypeName=NAME_None, ESocketType SocketType=ESocketType::SOCKTYPE_Unknown)=0
 
virtual SOCKETS_API void GetAddressInfoAsync (FAsyncGetAddressInfoCallback Callback, const TCHAR *HostName, const TCHAR *ServiceName=nullptr, EAddressInfoFlags QueryFlags=EAddressInfoFlags::Default, const FName ProtocolTypeName=NAME_None, ESocketType SocketType=ESocketType::SOCKTYPE_Unknown)
 
virtual TSharedPtr< FInternetAddrGetAddressFromString (const FString &InAddress)=0
 
virtual ESocketErrors GetHostByName (const ANSICHAR *HostName, FInternetAddr &OutAddr)
 
virtual SOCKETS_API class FResolveInfoGetHostByName (const ANSICHAR *HostName)
 
virtual bool RequiresChatDataBeSeparate ()=0
 
virtual bool RequiresEncryptedPackets ()=0
 
virtual bool GetHostName (FString &HostName)=0
 
virtual TSharedRef< FInternetAddrCreateInternetAddr (uint32 Address, uint32 Port=0)
 
virtual TSharedRef< FInternetAddrCreateInternetAddr ()=0
 
virtual TSharedRef< FInternetAddrCreateInternetAddr (const FName ProtocolType)
 
virtual SOCKETS_API TUniquePtr< FRecvMultiCreateRecvMulti (int32 MaxNumPackets, int32 MaxPacketSize, ERecvMultiFlags Flags=ERecvMultiFlags::None)
 
virtual bool HasNetworkDevice ()=0
 
virtual const TCHARGetSocketAPIName () const =0
 
virtual ESocketErrors GetLastErrorCode ()=0
 
virtual ESocketErrors TranslateErrorCode (int32 Code)=0
 
SOCKETS_API const TCHARGetSocketError (ESocketErrors Code=SE_GET_LAST_ERROR_CODE)
 
virtual SOCKETS_API bool GetLocalAdapterAddresses (TArray< TSharedPtr< FInternetAddr > > &OutAddresses)
 
virtual SOCKETS_API TSharedRef< FInternetAddrGetLocalBindAddr (FOutputDevice &Out)
 
virtual SOCKETS_API TArray< TSharedRef< FInternetAddr > > GetLocalBindAddresses ()
 
SOCKETS_API int32 BindNextPort (FSocket *Socket, FInternetAddr &Addr, int32 PortCount, int32 PortIncrement)
 
virtual SOCKETS_API TSharedRef< FInternetAddrGetLocalHostAddr (FOutputDevice &Out, bool &bCanBindAll)
 
virtual SOCKETS_API bool GetMultihomeAddress (TSharedRef< FInternetAddr > &Addr)
 
SOCKETS_API bool GetHostByNameFromCache (const ANSICHAR *HostName, TSharedPtr< class FInternetAddr > &Addr)
 
SOCKETS_API void AddHostNameToCache (const ANSICHAR *HostName, TSharedPtr< class FInternetAddr > Addr)
 
SOCKETS_API void RemoveHostNameFromCache (const ANSICHAR *HostName)
 
virtual SOCKETS_API bool IsSocketRecvMultiSupported () const
 
virtual bool IsSocketWaitSupported () const =0
 
virtual SOCKETS_API double TranslatePacketTimestamp (const FPacketTimestamp &Timestamp, ETimestampTranslation Translation=ETimestampTranslation::LocalTimestamp)
 
virtual SOCKETS_API bool IsRecvFromWithPktInfoSupported () const
 

Static Public Member Functions

static SOCKETS_API ISocketSubsystemGet (const FName &SubsystemName=NAME_None)
 
static SOCKETS_API void ShutdownAllSystems ()
 

Protected Member Functions

virtual SOCKETS_API ESocketProtocolFamily GetProtocolFamilyFromName (const FName &InProtocolName) const
 
virtual SOCKETS_API FName GetProtocolNameFromFamily (ESocketProtocolFamily InProtocolFamily) const
 

Detailed Description

This is the base interface to abstract platform specific sockets API differences.

Constructor & Destructor Documentation

◆ ISocketSubsystem()

ISocketSubsystem::ISocketSubsystem ( )
default

◆ ~ISocketSubsystem()

ISocketSubsystem::~ISocketSubsystem ( )
virtualdefault

Member Function Documentation

◆ AddHostNameToCache()

void ISocketSubsystem::AddHostNameToCache ( const ANSICHAR HostName,
TSharedPtr< class FInternetAddr Addr 
)

Stores the ip address with the matching host name

Parameters
HostNamethe host name to search for
Addrthe IP that will be copied from

◆ BindNextPort()

int32 ISocketSubsystem::BindNextPort ( FSocket Socket,
FInternetAddr Addr,
int32  PortCount,
int32  PortIncrement 
)

Bind to next available port.

Parameters
SocketThe socket that that will bind to the port
AddrThe local address and port that is being bound to (usually the result of GetLocalBindAddr()). This addresses port number will be modified in place
PortCountHow many ports to try
PortIncrementThe amount to increase the port number by on each attempt
Returns
The bound port number, or 0 on failure

◆ CreateInternetAddr() [1/3]

virtual TSharedRef< FInternetAddr > ISocketSubsystem::CreateInternetAddr ( )
pure virtual

Create a proper FInternetAddr representation

◆ CreateInternetAddr() [2/3]

virtual TSharedRef< FInternetAddr > ISocketSubsystem::CreateInternetAddr ( const FName  ProtocolType)
inlinevirtual

Create a FInternetAddr of the desired protocol

◆ CreateInternetAddr() [3/3]

virtual TSharedRef< FInternetAddr > ISocketSubsystem::CreateInternetAddr ( uint32  Address,
uint32  Port = 0 
)
inlinevirtual

Create a proper FInternetAddr representation

Parameters
Addresshost address
Porthost port

◆ CreateRecvMulti()

TUniquePtr< FRecvMulti > ISocketSubsystem::CreateRecvMulti ( int32  MaxNumPackets,
int32  MaxPacketSize,
ERecvMultiFlags  Flags = ERecvMultiFlags::None 
)
virtual

Create a platform specific FRecvMulti representation

Parameters
MaxNumPacketsThe maximum number of packet receives supported
MaxPacketSizeThe maximum supported packet size
FlagsFlags for specifying how FRecvMulti should be initialized (for e.g. retrieving timestamps)
Returns
Returns the platform specific FRecvMulti instance

◆ CreateResolveInfoCached()

FResolveInfoCached * ISocketSubsystem::CreateResolveInfoCached ( TSharedPtr< FInternetAddr Addr) const
virtual

Creates a resolve info cached struct to hold the resolved address

@Param Addr address to resolve for the socket subsystem

Returns
the new resolved address or NULL if failed

◆ CreateSocket() [1/3]

virtual FSocket * ISocketSubsystem::CreateSocket ( const FName SocketType,
const FString &  SocketDescription,
bool  bForceUDP = false 
)
inlinevirtual

Creates a socket

@Param SocketType type of socket to create (DGram, Stream, etc)

Parameters
SocketDescriptiondebug description
bForceUDPoverrides any platform specific protocol with UDP instead
Returns
the new socket or NULL if failed

◆ CreateSocket() [2/3]

virtual FSocket * ISocketSubsystem::CreateSocket ( const FName SocketType,
const FString &  SocketDescription,
const FName ProtocolName 
)
pure virtual

Creates a socket using the given protocol name.

@Param SocketType type of socket to create (DGram, Stream, etc)

Parameters
SocketDescriptiondebug description
ProtocolNamethe name of the internet protocol to use for this socket. None should be handled.
Returns
the new socket or NULL if failed

◆ CreateSocket() [3/3]

virtual FSocket * ISocketSubsystem::CreateSocket ( const FName SocketType,
const FString &  SocketDescription,
ESocketProtocolFamily  ProtocolType 
)
inlinevirtual

Creates a socket

@Param SocketType type of socket to create (DGram, Stream, etc)

Parameters
SocketDescriptiondebug description
ProtocolTypethe socket protocol to be used. Each subsystem must handle the None case and output a valid socket regardless.
Returns
the new socket or NULL if failed

◆ CreateUniqueSocket() [1/2]

FUniqueSocket ISocketSubsystem::CreateUniqueSocket ( const FName SocketType,
const FString &  SocketDescription,
bool  bForceUDP = false 
)

Creates a socket wrapped in a unique pointer that will call DestroySocket automatically - do not call it explicitly! This SocketSubsystem must also outlive the sockets it creates.

@Param SocketType type of socket to create (DGram, Stream, etc)

Parameters
SocketDescriptiondebug description
bForceUDPoverrides any platform specific protocol with UDP instead
Returns
the new socket or NULL if failed

◆ CreateUniqueSocket() [2/2]

FUniqueSocket ISocketSubsystem::CreateUniqueSocket ( const FName SocketType,
const FString &  SocketDescription,
const FName ProtocolName 
)

Creates a socket using the given protocol name, wrapped in a unique pointer that will call DestroySocket automatically - do not call it explicitly! This SocketSubsystem must also outlive the sockets it creates.

@Param SocketType type of socket to create (DGram, Stream, etc)

Parameters
SocketDescriptiondebug description
ProtocolNamethe name of the internet protocol to use for this socket. None should be handled.
Returns
the new socket or NULL if failed

◆ DestroySocket()

virtual void ISocketSubsystem::DestroySocket ( FSocket Socket)
pure virtual

Cleans up a socket class

Parameters
Socketthe socket object to destroy

◆ Get()

ISocketSubsystem * ISocketSubsystem::Get ( const FName SubsystemName = NAME_None)
static

Get the singleton socket subsystem for the given named subsystem

◆ GetAddressFromString()

virtual TSharedPtr< FInternetAddr > ISocketSubsystem::GetAddressFromString ( const FString &  InAddress)
pure virtual

Serializes a string that only contains an address.

This is a what you see is what you get, there is no DNS resolution of the input string, so only use this if you know you already have a valid address and will not need to convert. Otherwise, feed the address to GetAddressInfo for guaranteed results.

Parameters
InAddressthe address to serialize
Returns
The FInternetAddr of the given string address. This will point to nullptr on failure.

◆ GetAddressInfo() [1/2]

virtual FAddressInfoResult ISocketSubsystem::GetAddressInfo ( const TCHAR HostName,
const TCHAR ServiceName = nullptr,
EAddressInfoFlags  QueryFlags = EAddressInfoFlags::Default,
const FName  ProtocolTypeName = NAME_None,
ESocketType  SocketType = ESocketType::SOCKTYPE_Unknown 
)
pure virtual

Gets the address information of the given hostname and outputs it into an array of resolvable addresses. It is up to the caller to determine which one is valid for their environment.

This function allows for specifying FNames for the protocol type, allowing for support of other platform protocols

Parameters
HostNamestring version of the queryable hostname or ip address
ServiceNamestring version of a service name ("http") or a port number ("80")
QueryFlagsWhat flags are used in making the getaddrinfo call. Several flags can be used at once by bitwise OR-ing the flags together. Platforms are required to translate this value into a the correct flag representation.
ProtocolTypeNameUsed to limit results from the call. Specifying None will search all valid protocols. Callers will find they rarely have to specify this flag.
SocketTypeWhat socket type should the results be formatted for. This typically does not change any formatting results and can be safely left to the default value.
Returns
the results structure containing the array of address results to this query

◆ GetAddressInfo() [2/2]

virtual FAddressInfoResult ISocketSubsystem::GetAddressInfo ( const TCHAR HostName,
const TCHAR ServiceName = nullptr,
EAddressInfoFlags  QueryFlags = EAddressInfoFlags::Default,
ESocketProtocolFamily  ProtocolType = ESocketProtocolFamily::None,
ESocketType  SocketType = ESocketType::SOCKTYPE_Unknown 
)
inlinevirtual

Gets the address information of the given hostname and outputs it into an array of resolvable addresses. It is up to the caller to determine which one is valid for their environment.

Parameters
HostNamestring version of the queryable hostname or ip address
ServiceNamestring version of a service name ("http") or a port number ("80")
QueryFlagsWhat flags are used in making the getaddrinfo call. Several flags can be used at once by bitwise OR-ing the flags together. Platforms are required to translate this value into a the correct flag representation.
ProtocolTypeUsed to limit results from the call. Specifying None will search all valid protocols. Callers will find they rarely have to specify this flag.
SocketTypeWhat socket type should the results be formatted for. This typically does not change any formatting results and can be safely left to the default value.
Returns
the results structure containing the array of address results to this query

◆ GetAddressInfoAsync()

void ISocketSubsystem::GetAddressInfoAsync ( FAsyncGetAddressInfoCallback  Callback,
const TCHAR HostName,
const TCHAR ServiceName = nullptr,
EAddressInfoFlags  QueryFlags = EAddressInfoFlags::Default,
const FName  ProtocolTypeName = NAME_None,
ESocketType  SocketType = ESocketType::SOCKTYPE_Unknown 
)
virtual

Async variant of GetAddressInfo that fetches the data from the above function in an asynchronous task executed on an available background thread.

On Completion, this fires a callback function that will be executed on the same thread as the task's execution. The caller is responsible for either dispatching the result to the thread of their choosing or to allow the result callback execute on the task's thread.

This function allows for specifying FNames for the protocol type, allowing for support of other platform protocols

Parameters
Callbackthe callback function to fire when this query completes. Contains the FAddressInfoResult structure.
HostNamestring version of the queryable hostname or ip address
ServiceNamestring version of a service name ("http") or a port number ("80")
QueryFlagsWhat flags are used in making the getaddrinfo call. Several flags can be used at once by bitwise OR-ing the flags together. Platforms are required to translate this value into a the correct flag representation.
ProtocolTypeNameUsed to limit results from the call. Specifying None will search all valid protocols. Callers will find they rarely have to specify this flag.
SocketTypeWhat socket type should the results be formatted for. This typically does not change any formatting results and can be safely left to the default value.

◆ GetHostByName() [1/2]

FResolveInfo * ISocketSubsystem::GetHostByName ( const ANSICHAR HostName)
virtual

Creates a platform specific async hostname resolution object

Parameters
HostNamethe name of the host to look up
Returns
the resolve info to query for the address

◆ GetHostByName() [2/2]

virtual ESocketErrors ISocketSubsystem::GetHostByName ( const ANSICHAR HostName,
FInternetAddr OutAddr 
)
inlinevirtual

Does a DNS look up of a host name This code assumes a lot, and as such, it's not guaranteed that the results provided by it are correct.

Parameters
HostNamethe name of the host to look up
Addrthe address to copy the IP address to

◆ GetHostByNameFromCache()

bool ISocketSubsystem::GetHostByNameFromCache ( const ANSICHAR HostName,
TSharedPtr< class FInternetAddr > &  Addr 
)

Checks the host name cache for an existing entry (faster than resolving again)

Parameters
HostNamethe host name to search for
Addrthe out param that the IP will be copied to
Returns
true if the host was found, false otherwise

◆ GetHostName()

virtual bool ISocketSubsystem::GetHostName ( FString &  HostName)
pure virtual

Determines the name of the local machine

Parameters
HostNamethe string that receives the data
Returns
true if successful, false otherwise

◆ GetLastErrorCode()

virtual ESocketErrors ISocketSubsystem::GetLastErrorCode ( )
pure virtual

Returns the last error that has happened

◆ GetLocalAdapterAddresses()

bool ISocketSubsystem::GetLocalAdapterAddresses ( TArray< TSharedPtr< FInternetAddr > > &  OutAddresses)
virtual

Gets the list of addresses associated with the adapters on the local computer. Unlike GetLocalHostAddr, this function does not give preferential treatment to multihome options in results. It's encouraged that users check for multihome before using the results of this function.

Parameters
OutAddresses- Will hold the address list.
Returns
true on success, false otherwise.

◆ GetLocalBindAddr()

TSharedRef< FInternetAddr > ISocketSubsystem::GetLocalBindAddr ( FOutputDevice Out)
virtual

Get a local IP to bind to.

Typically, it is better to use GetLocalBindAddresses as it better supports hybrid network functionality and less chances for connections to fail due to mismatched protocols.

◆ GetLocalBindAddresses()

TArray< TSharedRef< FInternetAddr > > ISocketSubsystem::GetLocalBindAddresses ( )
virtual

Get bindable addresses that this machine can use as reported by GetAddressInfo with the BindableAddress flag. This will return the various any address for usage. If multihome has been specified, only the multihome address will be returned in the array.

Returns
If GetAddressInfo succeeded or multihome is specified, an array of addresses that can be binded on. Failure returns an empty array.

◆ GetLocalHostAddr()

TSharedRef< FInternetAddr > ISocketSubsystem::GetLocalHostAddr ( FOutputDevice Out,
bool bCanBindAll 
)
virtual

Uses the platform specific look up to determine the host address

To better support multiple network interfaces and remove ambiguity between address protocols, it is encouraged to use GetLocalAdapterAddresses to determine machine addresses. Be sure to check GetMultihomeAddress ahead of time.

Parameters
Outthe output device to log messages to
bCanBindAlltrue if all can be bound (no primarynet), false otherwise
Returns
The local host address

◆ GetMultihomeAddress()

bool ISocketSubsystem::GetMultihomeAddress ( TSharedRef< FInternetAddr > &  Addr)
virtual

Returns the multihome address if the flag is present and valid. For ease of use, this function will check validity of the address for the caller.

Parameters
Addrthe address structure which will have the Multihome address in it if set.
Returns
If the multihome address was set and valid

◆ GetProtocolFamilyFromName()

ESocketProtocolFamily ISocketSubsystem::GetProtocolFamilyFromName ( const FName InProtocolName) const
protectedvirtual

Conversion functions from the SocketProtocolFamily enum to the new FName system. For now, both are supported, but it's better to use the FName when possible.

◆ GetProtocolNameFromFamily()

FName ISocketSubsystem::GetProtocolNameFromFamily ( ESocketProtocolFamily  InProtocolFamily) const
protectedvirtual

◆ GetSocketAPIName()

virtual const TCHAR * ISocketSubsystem::GetSocketAPIName ( ) const
pure virtual

Get the name of the socket subsystem

Returns
a string naming this subsystem

◆ GetSocketError()

const TCHAR * ISocketSubsystem::GetSocketError ( ESocketErrors  Code = SE_GET_LAST_ERROR_CODE)

Returns a human readable string from an error code

Parameters
Codethe error code to check

◆ HasNetworkDevice()

virtual bool ISocketSubsystem::HasNetworkDevice ( )
pure virtual
Returns
Whether the machine has a properly configured network device or not

◆ Init()

virtual bool ISocketSubsystem::Init ( FString &  Error)
pure virtual

Does per platform initialization of the sockets library

Parameters
Errora string that is filled with error information
Returns
true if initialized ok, false otherwise

◆ IsRecvFromWithPktInfoSupported()

bool ISocketSubsystem::IsRecvFromWithPktInfoSupported ( ) const
virtual

Returns true if FSocket::RecvFromWithPktInfo is supported by this socket subsystem.

◆ IsSocketRecvMultiSupported()

bool ISocketSubsystem::IsSocketRecvMultiSupported ( ) const
virtual

Returns true if FSocket::RecvMulti is supported by this socket subsystem

◆ IsSocketWaitSupported()

virtual bool ISocketSubsystem::IsSocketWaitSupported ( ) const
pure virtual

Returns true if FSocket::Wait is supported by this socket subsystem.

◆ RemoveHostNameFromCache()

void ISocketSubsystem::RemoveHostNameFromCache ( const ANSICHAR HostName)

Removes the host name to ip mapping from the cache

Parameters
HostNamethe host name to search for

◆ RequiresChatDataBeSeparate()

virtual bool ISocketSubsystem::RequiresChatDataBeSeparate ( )
pure virtual

Some platforms require chat data (voice, text, etc.) to be placed into packets in a special way. This function tells the net connection whether this is required for this platform

◆ RequiresEncryptedPackets()

virtual bool ISocketSubsystem::RequiresEncryptedPackets ( )
pure virtual

Some platforms require packets be encrypted. This function tells the net connection whether this is required for this platform

◆ Shutdown()

virtual void ISocketSubsystem::Shutdown ( )
pure virtual

Performs platform specific socket clean up

◆ ShutdownAllSystems()

void ISocketSubsystem::ShutdownAllSystems ( )
static

Shutdown all registered subsystems

◆ TranslateErrorCode()

virtual ESocketErrors ISocketSubsystem::TranslateErrorCode ( int32  Code)
pure virtual

Translates the platform error code to a ESocketErrors enum

◆ TranslatePacketTimestamp()

double ISocketSubsystem::TranslatePacketTimestamp ( const FPacketTimestamp Timestamp,
ETimestampTranslation  Translation = ETimestampTranslation::LocalTimestamp 
)
virtual

Converts a platform packet timestamp, into a local timestamp, or into a time delta etc.

Parameters
TimestampThe timestamp to translate
TranslationThe type of translation to perform on the timestamp (time delta is usually faster than local timestamp)
Returns
Returns the translated timestamp or delta

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