FSocket

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

Windows
MacOS
Linux

References

Module

Sockets

Header

/Engine/Source/Runtime/Sockets/Public/Sockets.h

Include

#include "Sockets.h"

Syntax

class FSocket

Remarks

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

Variables

Name Description

Protected variable

FString

 

SocketDescription

Debug description of socket usage.

Protected variable

FName

 

SocketProtocol

Protocol used in creation of a socket

Protected variable

const ESocketTy...

 

SocketType

Indicates the type of socket this is

Constructors

Name Description

Public function

FSocket()

Default constructor.

Public function

FSocket

(
    ESocketType InSocketType,
    const FString& InSocketDescription
)

Please migrate to the constructor that specifies protocol stack

Public function

FSocket

(
    ESocketType InSocketType,
    const FString& InSocketDescription,
    ESocketProtocolFamily InSocketProto...
)

Please migrate to the constructor that takes an FName for the protocol stack

Public function

FSocket

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

Specifies the type of socket being created

Destructors

Name Description

Public function Virtual

~FSocket()

Virtual destructor.

Functions

Name Description

Public function

FSocket *...

 

Accept

(
    const FString& InSocketDescription
)

Accepts a connection that is pending.

Public function

FSocket *...

 

Accept

(
    FInternetAddr& OutAddr,
    const FString& InSocketDescription
)

Accepts a connection that is pending.

Public function

bool

 

Bind

(
    const FInternetAddr& Addr
)

Binds a socket to a network byte ordered address.

Public function

bool

 

Close()

Closes the socket

Public function

bool

 

Connect

(
    const FInternetAddr& Addr
)

Connects a socket to a network byte ordered address.

Public function

void

 

GetAddress

(
    FInternetAddr& OutAddr
)

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

Public function

ESocketConne...

 

GetConnectionState()

Determines the connection state of the socket.

Public function Const

FString

 

GetDescription()

Get the debug description of the socket.

Public function

bool

 

GetPeerAddress

(
    FInternetAddr& OutAddr
)

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

Public function

int32

 

GetPortNo()

Reads the port this socket is bound to.

Public function Const

FName

 

GetProtocol()

Get the type of protocol the socket is bound to

Public function Const

ESocketType

 

GetSocketType()

Get the type of protocol the socket is bound to

Public function

bool

 

HasPendingConnection

(
    bool& bHasPendingConnection
)

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

Public function

bool

 

HasPendingData

(
    uint32& PendingDataSize
)

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

Public function

bool

 

JoinMulticastGroup

(
    const FInternetAddr& GroupAddress,
    const FInternetAddr& InterfaceAddr...
)

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

Public function

bool

 

JoinMulticastGroup

(
    const FInternetAddr& GroupAddress
)

Joins this socket to the specified multicast group.

Public function

bool

 

LeaveMulticastGroup

(
    const FInternetAddr& GroupAddress
)

Removes this UDP client from the specified multicast group.

Public function

bool

 

LeaveMulticastGroup

(
    const FInternetAddr& GroupAddress,
    const FInternetAddr& InterfaceAddr...
)

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

Public function

bool

 

Listen

(
    int32 MaxBacklog
)

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

Public function Virtual

bool

 

Recv

(
    uint8* Data,
    int32 BufferSize,
    int32& BytesRead,
    ESocketReceiveFlags::Type Flags
)

Reads a chunk of data from a connected socket

Public function Virtual

bool

 

RecvFrom

(
    uint8* Data,
    int32 BufferSize,
    int32& BytesRead,
    FInternetAddr& Source,
    ESocketReceiveFlags::Type Flags
)

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

Public function Virtual

bool

 

RecvFromWithPktInfo

(
    uint8* Data,
    int32 BufferSize,
    int32& BytesRead,
    FInternetAddr& Source,
    FInternetAddr& Destination,
    ESocketReceiveFlags::Type Flags
)

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

Public function Virtual

bool

 

RecvMulti

(
    FRecvMulti& MultiData,
    ESocketReceiveFlags::Type Flags
)

Reads multiple packets from the socket at once, gathering the source address and other optional platform specific data.

Public function Virtual

bool

 

Send

(
    const uint8* Data,
    int32 Count,
    int32& BytesSent
)

Sends a buffer on a connected socket.

Public function Virtual

bool

 

SendTo

(
    const uint8* Data,
    int32 Count,
    int32& BytesSent,
    const FInternetAddr& Destination
)

Sends a buffer to a network byte ordered address.

Public function

bool

 

SetBroadcast

(
    bool bAllowBroadcast
)

Sets a socket into broadcast mode (UDP only).

Public function Virtual

bool

 

SetIpPktInfo

(
    bool bEnable
)

Sets whether to enable IP_PKTINFO support

Public function

bool

 

SetLinger

(
    bool bShouldLinger,
    int32 Timeout
)

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

Public function

bool

 

SetMulticastInterface

(
    const FInternetAddr& InterfaceAddr...
)

Sets the interface used to send outgoing multicast datagrams.

Public function

bool

 

SetMulticastLoopback

(
    bool bLoopback
)

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

Public function

bool

 

SetMulticastTtl

(
    uint8 TimeToLive
)

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

Public function

bool

 

SetNoDelay

(
    bool bIsNoDelay
)

Sets this socket into TCP_NODELAY mode (TCP only).

Public function

bool

 

SetNonBlocking

(
    bool bIsNonBlocking
)

Sets this socket into non-blocking mode.

Public function

bool

 

SetReceiveBufferSize

(
    int32 Size,
    int32& NewSize
)

Sets the size of the receive buffer to use.

Public function

bool

 

SetRecvErr

(
    bool bUseErrorQueue
)

Enables error queue support for the socket.

Public function Virtual

bool

 

SetRetrieveTimestamp

(
    bool bRetrieveTimestamp
)

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

Public function

bool

 

SetReuseAddr

(
    bool bAllowReuse
)

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

Public function

bool

 

SetSendBufferSize

(
    int32 Size,
    int32& NewSize
)

Sets the size of the send buffer to use.

Public function

bool

 

Shutdown

(
    ESocketShutdownMode Mode
)

Shuts down the socket, making it unusable for reads and/or writes.

Public function

bool

 

Wait

(
    ESocketWaitConditions::Type Conditi...,
    FTimespan WaitTime
)

Blocks until the specified condition is met.

Public function

bool

 

WaitForPendingConnection

(
    bool& bHasPendingConnection,
    const FTimespan& WaitTime
)

Waits for a pending connection on the socket.

Deprecated Functions

Name Description

Public function

 

FSocket

(
    ESocketType InSocketType,
    const FString& InSocketDescription
)

Please migrate to the constructor that specifies protocol stack

Public function

 

FSocket

(
    ESocketType InSocketType,
    const FString& InSocketDescription,
    ESocketProtocolFamily InSocketProto...
)

Please migrate to the constructor that takes an FName for the protocol stack

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss