FUdpSender和FUdpReceiver提供了一种更加便捷的方式来进行UDP消息的收发。
UdpSender
class FUdpSocketSender
: public FRunnable
, private FSingleThreadRunnable
FUdpSender继承于FRunnale和FSiungleThreadRunnable。
每次要发送的数据被封装成了一个包,如下结构。
// Structure for outbound packets.
struct FPacket
{
/** Holds the packet's data. */
TSharedPtr<TArray<uint8>, ESPMode::ThreadSafe> Data;
/** Holds the recipient. */
FIPv4Endpoint Recipient;
/** Default constructor. */
FPacket() { }
/** Creates and initializes a new instance. */
FPacket(const TSharedRef<TArray<uint8>, ESPMode::ThreadSafe>& InData, const FIPv4Endpoint& InRecipient)
: Data(InData)
, Recipient(InRecipient)
{ }
};
因为涉及到多线程访问数据,所以使用TSharedRef和TSharedPtr的线程安全版本。另外使用 IPv4Endpoint记录了一个要发送的目标socket地址。<