FSocket

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

Windows
MacOS
Linux

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

ESocketProtocol...

 

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...
)

Specifies the type of socket being created

Destructors

Name Description

Public function Virtual

~FSocket()

Virtual destructor.

Functions

Name Description

Public function

FSocket *...

 

Accept

(
    FInternetAddr& OutAddr,
    const FString& InSocketDescription
)

Accepts a connection that is pending.

Public function

FSocket *...

 

Accept

(
    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

ESocketProto...

 

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,
    const FInternetAddr& InterfaceAddr...
)

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

Public function

bool

 

LeaveMulticastGroup

(
    const FInternetAddr& GroupAddress
)

Removes this UDP client from the specified multicast group.

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

 

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

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

 

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

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

References

Module

Sockets

Header

Runtime/Sockets/Public/Sockets.h

Welcome to the new Unreal Engine 4 Documentation site!

We're working on lots of new features including a feedback system so you can tell us how we are doing. It's not quite ready for use in the wild yet, so head over to the Documentation Feedback forum to tell us about this page or call out any issues you are encountering in the meantime.

We'll be sure to let you know when the new system is up and running.

Post Feedback