-
Notifications
You must be signed in to change notification settings - Fork 16
UDPSubsystem
A class to handle receiving and sending data via UDP sockets and triggers the appropriate events
class UUDPSubsystem
: public UGameInstanceSubsystem
- Sockets/Public/IPAddress.h
- Common/UdpSocketBuilder.h
- Common/UdpSocketReceiver.h
- Common/UdpSocketSender.h
- CoreMinimal.h
- Subsystems/GameInstanceSubsystem.h
Access | Type | Name | Description | |
---|---|---|---|---|
Protected | TMap<int32, FReceiveSocketMapValue> | AllReceiveSockets | Map containing all opened receive sockets. | |
Protected | TMap<int32, FSocket*> | AllSendSockets | Map containing all opened send sockets. | |
Private | FString | LocalIPAddress | The IP address of the local machine | |
Protected | ISocketSubsystem* | SocketSubsystem | The socket subsystem. Used to open new sockets and close existing sockets. | |
Private | int | TotalReceiveSocketIterator | The count of how many receive sockets have been opened whether closed or not. | |
Private | int | TotalSendSocketIterator | The count of how many send sockets have been opened whether closed or not. |
Delegate Name | Event Name | Description |
---|---|---|
FUDPMessageSignature | OnReceivedBytes(const TArray<uint8>& Bytes, const FString& IPAddress) | Called after bytes are received by a bound UDP socket. |
FUDPReceiveSocketStateSignature | OnReceiveSocketClosed(int32 ReceiveSocketID, FString IpListeningOn, int32 PortListeningOn) | Called after a receive UDP socket has been closed. |
FUDPReceiveSocketStateSignature | OnReceiveSocketOpened(int32 ReceiveSocketID, FString IpListeningOn, int32 PortListeningOn) | Called after a new receive UDP socket is opened. |
FUDPSendSocketStateSignature | OnSendSocketClosed(int32 SendSocketID, FString LocalIp, int32 LocalPort, FString PeerIp, int32 PeerPort) | Called after a send UDP socket has been closed. |
FUDPSendSocketStateSignature | OnSendSocketOpened(int32 SendSocketID, FString LocalIp, int32 LocalPort, FString PeerIp, int32 PeerPort) | Called after a send UDP socket has been opened. |
Access | Return | Name | Description | |
---|---|---|---|---|
Public | bool | AnyConnectedSockets | Checks whether there are any connected receive or send sockets. | |
Public | bool | CloseAllReceiveSockets() | Closes all opened receive sockets. | |
Public | bool | CloseAllSendSockets() | Closes all opened send sockets. | |
Public | bool | CloseReceiveSocket(int32 ReceiveSocketIdToClose) | Closes the specified receive socket. | |
Public | bool | CloseSendSocket(int32 SendSocketIdToClose) | Closes the specified send socket. | |
Public | virtual | bool | Deinitialize() | Deinitialization of the subsystem. |
Public | bool | EmitBytes(const TArray<uint8>& Bytes) | Sends bytes over all opened send sockets. | |
Public | TArray<int32> | GetConnectedReceiveSocketIDs() | Gets the IDs of the connected receive sockets, if any. | |
Public | TArray<int32> | GetConnectedSendSocketIDs() | Gets the IDs of the connected send sockets, if any. | |
Public | virtual | bool | Initialize(FSubsystemCollectionBase& Collection) | Initialization of the subsystem. |
Public | bool | OpenReceiveSocket(FReceiveSocketSettings SocketSettings, int32& ReceiveSocketID, const FString& IpToListenOn, const int32 PortToListenOn) | Opens a new UDP receive socket at the given IP address and port. | |
Public | bool | OpenSendSocket(FSendSocketSettings SocketSettings, int32& SendSocketID, const FString& IpToSendOn, const int32 PortToSendOn)) | Opens a new UDP send socket at the given IP address and port. |
Name | Description |
---|---|
FReceiveSocketMapValue | Contains all needed information for UDP send sockets. |
FReceiveSocketSettings | Contains related settings needed for UDP receive sockets. |
FSendSocketSettings | Contains related settings needed for UDP send sockets. |
protected TMap<int32, FReceiveSocketMapValue> AllReceiveSockets
The mapping between opened receive sockets and their unique IDs.
protected TMap<int32, FSocket*> AllSendSockets
The mapping between opened send sockets and their unique IDs.
private FString LocalIPAddress
The IP address of the local machine.
protected ISocketSubsystem* SocketSubsystem
The socket subsystem. Used to open new sockets and close existing sockets.
private int TotalReceiveSocketIterator
The total number of receive sockets that have been opened whether closed or not.
private int TotalSendSocketIterator
The total number of send sockets that have been opened whether closed or not.
public FUDPMessageSignature OnReceivedBytes
Called after bytes are received by a bound UDP socket.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
Bytes | The bytes that were received by the UDP receiver |
IPAddress | The IP address that the message was received on |
public FUDPReceiveSocketStateSignature OnReceiveSocketClosed
Called after a receive UDP socket has been closed.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
ReceiveSocketID | The receive socket ID that was closed |
IpListeningOn | The IP address that the closed receive socket was listening on |
PortListeningOn | The port that the closed receive socket was listening on |
public FUDPReceiveSocketStateSignature OnReceiveSocketOpened
Called after a new receive UDP socket is opened.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
ReceiveSocketID | The receive socket ID that was opened |
IpListeningOn | The IP address that the opened receive socket is listening on |
PortListeningOn | The port that the opened receive socket is listening on |
public FUDPSendSocketStateSignature OnSendSocketClosed
Called after a send UDP socket has been closed.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
SendSocketID | The receive socket ID that was closed |
LocalIp | The local IP address that the closed send socket was on |
LocalPort | The local port that the closed send socket was on |
PeerIp | The local IP address that the closed send socket was sending to |
PeerPort | The local port that the closed send socket was sending to |
public FUDPSendSocketStateSignature OnSendSocketOpened
Called after a send UDP socket has been opened.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
SendSocketID | The receive socket ID that was opened |
LocalIp | The local IP address that the opened send socket is on |
LocalPort | The local port that the opened send socket is on |
PeerIp | The local IP address that the opened send socket is sending to |
PeerPort | The local port that the opened send socket is sending to |
public bool AnyConnectedSockets()
Checks whether there are any connected receive or send sockets.
Category: GRILL DIS|UDP Subsystem|Events
Returns |
---|
True if any sockets are connected, false otherwise |
public bool CloseAllReceiveSockets()
Closes all opened receive sockets.
Category: GRILL DIS|UDP Subsystem|Events
Returns |
---|
True all of the receive sockets were closed successfully. If none are opened, returns true. |
public bool CloseAllSendSockets()
Closes all opened send sockets.
Category: GRILL DIS|UDP Subsystem|Events
Returns |
---|
True all of the send sockets were closed successfully. If none are opened, returns true. |
public bool CloseReceiveSocket
(
int32 ReceiveSocketIdToClose
)
Closes the opened receive socket with the given ID.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
ReceiveSocketIdToClose | The ID of the receive socket to close |
Returns |
---|
True if the receive socket was closed successfully. If none exist with the ID, returns true. |
public bool CloseSendSocket
(
int32 SendSocketIdToClose
)
Closes the opened send socket with the given ID.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
SendSocketIdToClose | The ID of the send socket to close |
Returns |
---|
True if the send socket was closed successfully. If none exist with the ID, returns true. |
public virtual void Deinitialize() override
Deinitializes the subsystem.
public bool EmitBytes
(
const TArray<uint8>& Bytes
)
Sends bytes over all opened send sockets.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
Bytes | The bytes to emit over the send sockets. |
Returns |
---|
True if the sending was successful for every opened socket. |
public TArray<int32> GetConnectedReceiveSocketIDs()
Gets the IDs of the connected receive sockets, if any.
Category: GRILL DIS|UDP Subsystem|Events
Returns |
---|
An array containing all of the IDs of the connected receive sockets. |
public TArray<int32> GetConnectedSendSocketIDs()
Gets the IDs of the connected send sockets, if any.
Category: GRILL DIS|UDP Subsystem|Events
Returns |
---|
An array containing all of the IDs of the connected send sockets. |
public virtual void Initialize
(
FSubsystemCollectionBase& Collection
) override
Initialization of the subsystem.
Parameter | Description |
---|---|
Collection | The collection of all subsystems. |
public bool OpenReceiveSocket
(
FReceiveSocketSettings SocketSettings,
int32& ReceiveSocketID,
const FString& IpToListenOn = TEXT("0.0.0.0"),
const int32 PortToListenOn = 3001
)
Opens a new UDP receive socket at the given IP address and port. Closes an opened connection if there was one prior to creating a new one.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
SocketSettings | The settings this seocket should utilize. |
ReceiveSocketID | The ID of the opened receive socket. |
IpToListenOn | The IP address to receive UDP packets to. |
PortToListenOn | The port to receive UDP packets on. |
Returns |
---|
Whether or not the receive socket was opened successfully. |
public bool OpenSendSocket
(
FSendSocketSettings SocketSettings,
int32& SendSocketID,
const FString& IpToSendOn = TEXT("127.0.0.1"),
const int32 PortToSendOn = 3000
)
Opens a new UDP send socket at the given IP address and port. Closes an opened connection if there was one prior to creating a new one.
Category: GRILL DIS|UDP Subsystem|Events
Parameter | Description |
---|---|
SocketSettings | The settings this seocket should utilize. |
SendSocketID | The ID of the opened send socket. |
IpToSendOn | The IP address to send UDP packets to. |
PortToSendOn | The port to send UDP packets on. |
Returns |
---|
Whether or not the send socket was opened successfully. |