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

#include <Sockets.h>

+ Inheritance diagram for FSocket:

Public Member Functions

SOCKETS_API FSocket ()
 
 FSocket (ESocketType InSocketType, const FString &InSocketDescription)
 
 FSocket (ESocketType InSocketType, const FString &InSocketDescription, ESocketProtocolFamily InSocketProtocol)
 
SOCKETS_API FSocket (ESocketType InSocketType, const FString &InSocketDescription, const FName &InSocketProtocol)
 
virtual SOCKETS_API ~FSocket ()
 
virtual bool Shutdown (ESocketShutdownMode Mode)=0
 
virtual bool Close ()=0
 
virtual UPTRINT ReleaseNativeSocket ()
 
virtual bool Bind (const FInternetAddr &Addr)=0
 
virtual bool Connect (const FInternetAddr &Addr)=0
 
virtual bool Listen (int32 MaxBacklog)=0
 
virtual bool WaitForPendingConnection (bool &bHasPendingConnection, const FTimespan &WaitTime)=0
 
bool HasPendingConnection (bool &bHasPendingConnection)
 
virtual bool HasPendingData (uint32 &PendingDataSize)=0
 
virtual class FSocketAccept (const FString &InSocketDescription)=0
 
virtual class FSocketAccept (FInternetAddr &OutAddr, const FString &InSocketDescription)=0
 
virtual SOCKETS_API bool SendTo (const uint8 *Data, int32 Count, int32 &BytesSent, const FInternetAddr &Destination)
 
virtual SOCKETS_API bool Send (const uint8 *Data, int32 Count, int32 &BytesSent)
 
virtual SOCKETS_API bool RecvFrom (uint8 *Data, int32 BufferSize, int32 &BytesRead, FInternetAddr &Source, ESocketReceiveFlags::Type Flags=ESocketReceiveFlags::None)
 
virtual SOCKETS_API bool Recv (uint8 *Data, int32 BufferSize, int32 &BytesRead, ESocketReceiveFlags::Type Flags=ESocketReceiveFlags::None)
 
virtual SOCKETS_API bool RecvMulti (FRecvMulti &MultiData, ESocketReceiveFlags::Type Flags=ESocketReceiveFlags::None)
 
virtual bool Wait (ESocketWaitConditions::Type Condition, FTimespan WaitTime)=0
 
virtual ESocketConnectionState GetConnectionState ()=0
 
virtual void GetAddress (FInternetAddr &OutAddr)=0
 
virtual bool GetPeerAddress (FInternetAddr &OutAddr)=0
 
virtual bool SetNonBlocking (bool bIsNonBlocking=true)=0
 
virtual bool SetBroadcast (bool bAllowBroadcast=true)=0
 
virtual bool SetNoDelay (bool bIsNoDelay=true)=0
 
virtual bool JoinMulticastGroup (const FInternetAddr &GroupAddress)=0
 
virtual bool JoinMulticastGroup (const FInternetAddr &GroupAddress, const FInternetAddr &InterfaceAddress)=0
 
virtual bool LeaveMulticastGroup (const FInternetAddr &GroupAddress)=0
 
virtual bool LeaveMulticastGroup (const FInternetAddr &GroupAddress, const FInternetAddr &InterfaceAddress)=0
 
virtual bool SetMulticastLoopback (bool bLoopback)=0
 
virtual bool SetMulticastTtl (uint8 TimeToLive)=0
 
virtual bool SetMulticastInterface (const FInternetAddr &InterfaceAddress)=0
 
virtual bool SetReuseAddr (bool bAllowReuse=true)=0
 
virtual bool SetLinger (bool bShouldLinger=true, int32 Timeout=0)=0
 
virtual bool SetRecvErr (bool bUseErrorQueue=true)=0
 
virtual bool SetSendBufferSize (int32 Size, int32 &NewSize)=0
 
virtual bool SetReceiveBufferSize (int32 Size, int32 &NewSize)=0
 
virtual SOCKETS_API bool SetRetrieveTimestamp (bool bRetrieveTimestamp=true)
 
virtual int32 GetPortNo ()=0
 
virtual SOCKETS_API bool SetIpPktInfo (bool bEnable)
 
virtual SOCKETS_API bool RecvFromWithPktInfo (uint8 *Data, int32 BufferSize, int32 &BytesRead, FInternetAddr &Source, FInternetAddr &Destination, ESocketReceiveFlags::Type Flags=ESocketReceiveFlags::None)
 
ESocketType GetSocketType () const
 
FString GetDescription () const
 
FName GetProtocol () const
 
- Public Member Functions inherited from TSharedFromThis< FSocket, ESPMode::ThreadSafe >
TSharedRef< FSocket, Mode > AsShared ()
 
TSharedRef< FSocket const, Mode > AsShared () const
 
TSharedRef< SubobjectType, Mode > AsSharedSubobject (SubobjectType *SubobjectPtr) const
 
TWeakPtr< FSocket, Mode > AsWeak ()
 
TWeakPtr< FSocket const, Mode > AsWeak () const
 
TWeakPtr< SubobjectType, Mode > AsWeakSubobject (SubobjectType *SubobjectPtr) const
 
void UpdateWeakReferenceInternal (TSharedPtr< SharedPtrType, SharedPtrMode > const *InSharedPtr, OtherType *InObject) const
 
void UpdateWeakReferenceInternal (TSharedRef< SharedRefType, SharedPtrMode > const *InSharedRef, OtherType *InObject) const
 
UE_FORCEINLINE_HINT bool DoesSharedInstanceExist () const
 

Protected Attributes

const ESocketType SocketType
 
FString SocketDescription
 
FName SocketProtocol
 

Additional Inherited Members

- Protected Member Functions inherited from TSharedFromThis< FSocket, ESPMode::ThreadSafe >
 TSharedFromThis ()
 
 TSharedFromThis (TSharedFromThis const &)
 
UE_FORCEINLINE_HINT TSharedFromThisoperator= (TSharedFromThis const &)
 
 ~TSharedFromThis ()
 
- Static Protected Member Functions inherited from TSharedFromThis< FSocket, ESPMode::ThreadSafe >
static UE_FORCEINLINE_HINT TSharedRef< OtherType, Mode > SharedThis (OtherType *ThisPtr)
 
static UE_FORCEINLINE_HINT TSharedRef< OtherType const, Mode > SharedThis (const OtherType *ThisPtr)
 

Detailed Description

This is our abstract base class that hides the platform specific socket implementation

Constructor & Destructor Documentation

◆ FSocket() [1/4]

FSocket::FSocket ( )

Default constructor.

◆ FSocket() [2/4]

FSocket::FSocket ( ESocketType  InSocketType,
const FString &  InSocketDescription 
)
inline

Specifies the type of socket being created

Parameters
InSocketTypeThe type of socket being created
InSocketDescriptionThe debug description of the socket

◆ FSocket() [3/4]

FSocket::FSocket ( ESocketType  InSocketType,
const FString &  InSocketDescription,
ESocketProtocolFamily  InSocketProtocol 
)
inline

◆ FSocket() [4/4]

FSocket::FSocket ( ESocketType  InSocketType,
const FString &  InSocketDescription,
const FName InSocketProtocol 
)

Specifies the type of socket being created

Parameters
InSocketTypeThe type of socket being created
InSocketDescriptionThe debug description of the socket
InSocketProtocolthe protocol stack this socket should be created on.

◆ ~FSocket()

FSocket::~FSocket ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ Accept() [1/2]

virtual class FSocket * FSocket::Accept ( const FString &  InSocketDescription)
pure virtual

Accepts a connection that is pending.

Parameters
SocketDescriptionDebug description of socket,
Returns
The new (heap-allocated) socket, or nullptr if unsuccessful.

◆ Accept() [2/2]

virtual class FSocket * FSocket::Accept ( FInternetAddr OutAddr,
const FString &  InSocketDescription 
)
pure virtual

Accepts a connection that is pending.

Parameters
OutAddrThe address of the connection.
SocketDescriptionDebug description of socket.
Returns
The new (heap-allocated) socket, or nullptr if unsuccessful.

◆ Bind()

virtual bool FSocket::Bind ( const FInternetAddr Addr)
pure virtual

Binds a socket to a network byte ordered address.

Parameters
AddrThe address to bind to.
Returns
true if successful, false otherwise.

◆ Close()

virtual bool FSocket::Close ( )
pure virtual

Closes the socket

Returns
true if it closes without errors, false otherwise.

◆ Connect()

virtual bool FSocket::Connect ( const FInternetAddr Addr)
pure virtual

Connects a socket to a network byte ordered address.

Parameters
AddrThe address to connect to.
Returns
true if successful, false otherwise.

◆ GetAddress()

virtual void FSocket::GetAddress ( FInternetAddr OutAddr)
pure virtual

Reads the address the socket is bound to and returns it.

Parameters
OutAddrThe address the socket is bound to.

◆ GetConnectionState()

virtual ESocketConnectionState FSocket::GetConnectionState ( )
pure virtual

Determines the connection state of the socket.

Returns
Connection state.

◆ GetDescription()

FString FSocket::GetDescription ( ) const
inline

Get the debug description of the socket.

Returns
Debug string.
See also
GetPortNo, GetSocketType

◆ GetPeerAddress()

virtual bool FSocket::GetPeerAddress ( FInternetAddr OutAddr)
pure virtual

Reads the address of the peer the socket is connected to.

Parameters
OutAddrAddress of the peer the socket is connected to.
Returns
true if the address was retrieved correctly, false otherwise.

◆ GetPortNo()

virtual int32 FSocket::GetPortNo ( )
pure virtual

Reads the port this socket is bound to.

Returns
Port number.
See also
GetSocketType, GetDescription

◆ GetProtocol()

FName FSocket::GetProtocol ( ) const
inline

Get the type of protocol the socket is bound to

Returns
Socket type.
See also
GetDescription, GetPortNo

◆ GetSocketType()

ESocketType FSocket::GetSocketType ( ) const
inline

Get the type of protocol the socket is bound to

Returns
Socket type.
See also
GetDescription, GetPortNo

◆ HasPendingConnection()

bool FSocket::HasPendingConnection ( bool bHasPendingConnection)
inline

Queries the socket to determine if there is a pending connection.

Parameters
bHasPendingConnectionWill indicate whether a connection is pending or not.
Returns
true if successful, false otherwise.

◆ HasPendingData()

virtual bool FSocket::HasPendingData ( uint32 PendingDataSize)
pure virtual

Queries the socket to determine if there is pending data on the queue.

Parameters
PendingDataSizeWill indicate how much data is on the pipe for a single recv call.
Returns
true if the socket has data, false otherwise.

◆ JoinMulticastGroup() [1/2]

virtual bool FSocket::JoinMulticastGroup ( const FInternetAddr GroupAddress)
pure virtual

Joins this socket to the specified multicast group.

The multicast group address must be in the range 224.0.0.0 to 239.255.255.255.

Parameters
GroupAddressThe IP address of the multicast group.
Returns
true on success, false otherwise.
See also
LeaveMulticastGroup, SetMulticastLoopback, SetMulticastTtl

◆ JoinMulticastGroup() [2/2]

virtual bool FSocket::JoinMulticastGroup ( const FInternetAddr GroupAddress,
const FInternetAddr InterfaceAddress 
)
pure virtual

Joins this socket to the specified multicast group on the specified interface.

The multicast group address must be in the range 224.0.0.0 to 239.255.255.255.

Parameters
GroupAddressThe IP address of the multicast group.
InterfaceAddressThe address representing the interface.
Returns
true on success, false otherwise.
See also
LeaveMulticastGroup, SetMulticastLoopback, SetMulticastTtl

◆ LeaveMulticastGroup() [1/2]

virtual bool FSocket::LeaveMulticastGroup ( const FInternetAddr GroupAddress)
pure virtual

Removes this UDP client from the specified multicast group.

Parameters
Themulticast group address to leave.
Returns
true on success, false otherwise.
See also
JoinMulticastGroup, SetMulticastLoopback, SetMulticastTtl

◆ LeaveMulticastGroup() [2/2]

virtual bool FSocket::LeaveMulticastGroup ( const FInternetAddr GroupAddress,
const FInternetAddr InterfaceAddress 
)
pure virtual

Removes this UDP client from the specified multicast group on the specified interface.

Parameters
GroupAddressThe multicast group address to leave.
InterfaceAddressThe address representing the interface.
Returns
true on success, false otherwise.
See also
JoinMulticastGroup, SetMulticastLoopback, SetMulticastTtl

◆ Listen()

virtual bool FSocket::Listen ( int32  MaxBacklog)
pure virtual

Places the socket into a state to listen for incoming connections.

Parameters
MaxBacklogThe number of connections to queue before refusing them.
Returns
true if successful, false otherwise.

◆ Recv()

bool FSocket::Recv ( uint8 Data,
int32  BufferSize,
int32 BytesRead,
ESocketReceiveFlags::Type  Flags = ESocketReceiveFlags::None 
)
virtual

Reads a chunk of data from a connected socket

A return value of 'true' does not necessarily mean that data was returned. Callers must check the 'BytesRead' parameter for the actual amount of data returned. A value of zero indicates that there was no data available for reading.

Parameters
DataThe buffer to read into
BufferSizeThe max size of the buffer
BytesReadWill indicate how many bytes were read from the socket
Flagsthe receive flags
Returns
true on success, false in case of a closed socket or an unrecoverable error.

◆ RecvFrom()

bool FSocket::RecvFrom ( uint8 Data,
int32  BufferSize,
int32 BytesRead,
FInternetAddr Source,
ESocketReceiveFlags::Type  Flags = ESocketReceiveFlags::None 
)
virtual

Reads a chunk of data from the socket and gathers the source address.

A return value of 'true' does not necessarily mean that data was returned. Callers must check the 'BytesRead' parameter for the actual amount of data returned. A value of zero indicates that there was no data available for reading.

Parameters
DataThe buffer to read into.
BufferSizeThe max size of the buffer.
BytesReadWill indicate how many bytes were read from the socket.
SourceWill contain the receiving the address of the sender of the data.
FlagsThe receive flags.
Returns
true on success, false in case of a closed socket or an unrecoverable error.

◆ RecvFromWithPktInfo()

bool FSocket::RecvFromWithPktInfo ( uint8 Data,
int32  BufferSize,
int32 BytesRead,
FInternetAddr Source,
FInternetAddr Destination,
ESocketReceiveFlags::Type  Flags = ESocketReceiveFlags::None 
)
virtual

Reads a chunk of data from the socket and gathers the source address and the destination using IP_PKTINFO

A return value of 'true' does not necessarily mean that data was returned. Callers must check the 'BytesRead' parameter for the actual amount of data returned. A value of zero indicates that there was no data available for reading.

Parameters
DataThe buffer to read into.
BufferSizeThe max size of the buffer.
BytesReadWill indicate how many bytes were read from the socket.
SourceWill contain the receiving the address of the sender of the data.
DestinationWill contain the destination address used by the sender of the data.
FlagsThe receive flags.
Returns
true on success, false in case of a closed socket or an unrecoverable error.

◆ RecvMulti()

bool FSocket::RecvMulti ( FRecvMulti MultiData,
ESocketReceiveFlags::Type  Flags = ESocketReceiveFlags::None 
)
virtual

Reads multiple packets from the socket at once, gathering the source address and other optional platform specific data. Use ISocketSubsystem::IsSocketRecvMultiSupported to check if the current socket platform supports this. NOTE: For optimal performance, one FRecvMulti instance should be used, for the lifetime of the socket.

Parameters
MultiDataThe FRecvMulti instance that receives packet data and holds platform specific buffers for receiving data.
FlagsThe receive flags.
Returns
Whether or not data was successfully received

◆ ReleaseNativeSocket()

virtual UPTRINT FSocket::ReleaseNativeSocket ( )
inlinevirtual

Releases the underlying socket implementation for use with native APIs. The user of this class must know the underlying implementation details in order to cast the return value properly. If this function succeeds, the FSocket instance no longer controls the connection (it will not Close()).

Returns
a non-zero value upon success, or zero if not implemented/failure to release ownership.

◆ Send()

bool FSocket::Send ( const uint8 Data,
int32  Count,
int32 BytesSent 
)
virtual

Sends a buffer on a connected socket.

Parameters
DataThe buffer to send.
CountThe size of the data to send.
BytesSentWill indicate how much was sent.

◆ SendTo()

bool FSocket::SendTo ( const uint8 Data,
int32  Count,
int32 BytesSent,
const FInternetAddr Destination 
)
virtual

Sends a buffer to a network byte ordered address.

Parameters
DataThe buffer to send.
CountThe size of the data to send.
BytesSentWill indicate how much was sent.
DestinationThe network byte ordered address to send to.

◆ SetBroadcast()

virtual bool FSocket::SetBroadcast ( bool  bAllowBroadcast = true)
pure virtual

Sets a socket into broadcast mode (UDP only).

Parameters
bAllowBroadcastWhether to enable broadcast or not.
Returns
true if successful, false otherwise.

◆ SetIpPktInfo()

bool FSocket::SetIpPktInfo ( bool  bEnable)
virtual

Sets whether to enable IP_PKTINFO support

Parameters
bEnableWhether to enable/disable
Returns
True if the call succeeded, false otherwise.

◆ SetLinger()

virtual bool FSocket::SetLinger ( bool  bShouldLinger = true,
int32  Timeout = 0 
)
pure virtual

Sets whether and how long a socket will linger after closing.

Parameters
bShouldLingerWhether to have the socket remain open for a time period after closing or not.
TimeoutThe amount of time to linger before closing.
Returns
true if the call succeeded, false otherwise.

◆ SetMulticastInterface()

virtual bool FSocket::SetMulticastInterface ( const FInternetAddr InterfaceAddress)
pure virtual

Sets the interface used to send outgoing multicast datagrams.

Multicast traffic is sent using the default interface, this allows to explicitly set the interface used to send outgoing multicast datagrams.

Parameters
InterfaceAddressThe interface address.
Returns
true if the call succeeded, false otherwise.

◆ SetMulticastLoopback()

virtual bool FSocket::SetMulticastLoopback ( bool  bLoopback)
pure virtual

Enables or disables multicast loopback on the socket (UDP only).

This setting determines whether multicast datagrams are looped back to the sending socket. By default, multicast loopback is enabled. It must be enabled if more than one listener is present on a host.

Parameters
bLoopbackWhether loopback should be enabled.
See also
LeaveMulticastGroup, JoinMulticastGroup, SetMulticastTtl

◆ SetMulticastTtl()

virtual bool FSocket::SetMulticastTtl ( uint8  TimeToLive)
pure virtual

Sets the time to live (TTL) for multicast datagrams.

The default TTL for multicast datagrams is 1, which prevents them from being forwarded beyond the local subnet. Higher values will allow multicast datagrams to be sent into neighboring subnets, if multicast capable routers are present.

Parameters
TimeToLiveNumber of hops the datagram can make.
See also
LeaveMulticastGroup, JoinMulticastGroup, SetMulticastLoopback

◆ SetNoDelay()

virtual bool FSocket::SetNoDelay ( bool  bIsNoDelay = true)
pure virtual

Sets this socket into TCP_NODELAY mode (TCP only).

Parameters
bIsNoDelayWhether to enable no delay mode.
Returns
true if successful, false otherwise.

◆ SetNonBlocking()

virtual bool FSocket::SetNonBlocking ( bool  bIsNonBlocking = true)
pure virtual

Sets this socket into non-blocking mode.

Parameters
bIsNonBlockingWhether to enable blocking or not.
Returns
true if successful, false otherwise.

◆ SetReceiveBufferSize()

virtual bool FSocket::SetReceiveBufferSize ( int32  Size,
int32 NewSize 
)
pure virtual

Sets the size of the receive buffer to use.

Parameters
SizeThe size to change it to.
NewSizeWill contain the size that was set (in case OS can't set that).
Returns
true if the call succeeded, false otherwise.

◆ SetRecvErr()

virtual bool FSocket::SetRecvErr ( bool  bUseErrorQueue = true)
pure virtual

Enables error queue support for the socket.

Parameters
bUseErrorQueueWhether to enable error queuing or not.
Returns
true if the call succeeded, false otherwise.

◆ SetRetrieveTimestamp()

bool FSocket::SetRetrieveTimestamp ( bool  bRetrieveTimestamp = true)
virtual

Sets whether to retrieve the system-level receive timestamp, for sockets

Parameters
bRetrieveTimestampWhether to retrieve the timestamp upon receive
Returns
True if the call succeeded, false otherwise.

◆ SetReuseAddr()

virtual bool FSocket::SetReuseAddr ( bool  bAllowReuse = true)
pure virtual

Sets whether a socket can be bound to an address in use.

Parameters
bAllowReuseWhether to allow reuse or not.
Returns
true if the call succeeded, false otherwise.

◆ SetSendBufferSize()

virtual bool FSocket::SetSendBufferSize ( int32  Size,
int32 NewSize 
)
pure virtual

Sets the size of the send buffer to use.

Parameters
SizeThe size to change it to.
NewSizeWill contain the size that was set (in case OS can't set that).
Returns
true if the call succeeded, false otherwise.

◆ Shutdown()

virtual bool FSocket::Shutdown ( ESocketShutdownMode  Mode)
pure virtual

Shuts down the socket, making it unusable for reads and/or writes. This does not close the socket!

Parameters
Types
Returns
true if successful, false otherwise.

◆ Wait()

virtual bool FSocket::Wait ( ESocketWaitConditions::Type  Condition,
FTimespan  WaitTime 
)
pure virtual

Blocks until the specified condition is met.

Parameters
ConditionThe condition to wait for.
WaitTimeThe maximum time to wait.
Returns
true if the condition was met, false if the time limit expired or an error occurred.

◆ WaitForPendingConnection()

virtual bool FSocket::WaitForPendingConnection ( bool bHasPendingConnection,
const FTimespan WaitTime 
)
pure virtual

Waits for a pending connection on the socket.

Parameters
outbHasPendingConnection Will indicate whether a connection is pending or not.
WaitTimeThe maximum time to wait for a connection. If zero, the function will not wait and will return immediately with a value in bHasPendingConnection.
Returns
true if successful, false otherwise.

Member Data Documentation

◆ SocketDescription

FString FSocket::SocketDescription
protected

Debug description of socket usage.

◆ SocketProtocol

FName FSocket::SocketProtocol
protected

Protocol used in creation of a socket

◆ SocketType

const ESocketType FSocket::SocketType
protected

Indicates the type of socket this is


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