From af944c5b8677ac747189b1a8a4235e5cf8a7d65a Mon Sep 17 00:00:00 2001 From: _Redstone_c_ <2824517378@qq.com> Date: Thu, 7 Jan 2021 20:51:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=8E=B7=E5=8F=96=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=20Socket=20=E7=9A=84=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RedNetwork/Private/RedNetworkServer.cpp | 21 +++++++++++++++++++ Source/RedNetwork/Public/RedNetworkServer.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/Source/RedNetwork/Private/RedNetworkServer.cpp b/Source/RedNetwork/Private/RedNetworkServer.cpp index 2bfebcc..7446b97 100644 --- a/Source/RedNetwork/Private/RedNetworkServer.cpp +++ b/Source/RedNetwork/Private/RedNetworkServer.cpp @@ -17,6 +17,27 @@ bool URedNetworkServer::Send(int32 ClientID, const TArray& Data) return Info.KCPUnit->Send(Data.GetData(), Data.Num()) == 0; } +TSharedPtr URedNetworkServer::GetSocketAddr() const +{ + if (!SocketPtr) return nullptr; + + ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(); + check(SocketSubsystem); + + TSharedRef Addr = SocketSubsystem->CreateInternetAddr(); + + SocketPtr->GetAddress(*Addr); + + return Addr; +} + +FString URedNetworkServer::GetSocketAddrString() const +{ + TSharedPtr Addr = GetSocketAddr(); + + return Addr ? Addr->ToString(true) : TEXT(""); +} + void URedNetworkServer::UDPSend(int32 ClientID, const uint8* Data, int32 Count) { if (!IsActive() || !Connections.Contains(ClientID)) return; diff --git a/Source/RedNetwork/Public/RedNetworkServer.h b/Source/RedNetwork/Public/RedNetworkServer.h index 641febf..5166273 100644 --- a/Source/RedNetwork/Public/RedNetworkServer.h +++ b/Source/RedNetwork/Public/RedNetworkServer.h @@ -46,6 +46,11 @@ public: UFUNCTION(BlueprintCallable, Category = "Red|Network") bool Send(int32 ClientID, const TArray& Data); + TSharedPtr GetSocketAddr() const; + + UFUNCTION(BlueprintCallable, Category = "Red|Network") + FString GetSocketAddrString() const; + public: UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Red|Network")