允许获取服务器 Socket 的地址

This commit is contained in:
_Redstone_c_ 2021-01-07 20:51:11 +08:00
parent 2cd3447821
commit af944c5b86
2 changed files with 26 additions and 0 deletions

View File

@ -17,6 +17,27 @@ bool URedNetworkServer::Send(int32 ClientID, const TArray<uint8>& Data)
return Info.KCPUnit->Send(Data.GetData(), Data.Num()) == 0;
}
TSharedPtr<FInternetAddr> URedNetworkServer::GetSocketAddr() const
{
if (!SocketPtr) return nullptr;
ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get();
check(SocketSubsystem);
TSharedRef<FInternetAddr> Addr = SocketSubsystem->CreateInternetAddr();
SocketPtr->GetAddress(*Addr);
return Addr;
}
FString URedNetworkServer::GetSocketAddrString() const
{
TSharedPtr<FInternetAddr> Addr = GetSocketAddr();
return Addr ? Addr->ToString(true) : TEXT("");
}
void URedNetworkServer::UDPSend(int32 ClientID, const uint8* Data, int32 Count)
{
if (!IsActive() || !Connections.Contains(ClientID)) return;

View File

@ -46,6 +46,11 @@ public:
UFUNCTION(BlueprintCallable, Category = "Red|Network")
bool Send(int32 ClientID, const TArray<uint8>& Data);
TSharedPtr<FInternetAddr> GetSocketAddr() const;
UFUNCTION(BlueprintCallable, Category = "Red|Network")
FString GetSocketAddrString() const;
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Red|Network")