允许获取服务器 Socket 的地址
This commit is contained in:
parent
2cd3447821
commit
af944c5b86
@ -17,6 +17,27 @@ bool URedNetworkServer::Send(int32 ClientID, const TArray<uint8>& Data)
|
|||||||
return Info.KCPUnit->Send(Data.GetData(), Data.Num()) == 0;
|
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)
|
void URedNetworkServer::UDPSend(int32 ClientID, const uint8* Data, int32 Count)
|
||||||
{
|
{
|
||||||
if (!IsActive() || !Connections.Contains(ClientID)) return;
|
if (!IsActive() || !Connections.Contains(ClientID)) return;
|
||||||
|
@ -46,6 +46,11 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = "Red|Network")
|
UFUNCTION(BlueprintCallable, Category = "Red|Network")
|
||||||
bool Send(int32 ClientID, const TArray<uint8>& Data);
|
bool Send(int32 ClientID, const TArray<uint8>& Data);
|
||||||
|
|
||||||
|
TSharedPtr<FInternetAddr> GetSocketAddr() const;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Red|Network")
|
||||||
|
FString GetSocketAddrString() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Red|Network")
|
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Red|Network")
|
||||||
|
Reference in New Issue
Block a user