Skip to content

Commit 4106b11

Browse files
committed
[Versions] Added versions for 4.27 & 5.00
1 parent fbcfde6 commit 4106b11

30 files changed

+863
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"BuildId": "17155196",
3+
"Modules":
4+
{
5+
"UDPCommunication": "UE4Editor-UDPCommunication-0001.dll"
6+
}
7+
}
7.29 KB
Loading
7.29 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#pragma once
2+
3+
#include "Serialization/Archive.h"
4+
#include "UDPData.generated.h"
5+
6+
USTRUCT(BlueprintType)
7+
struct FUDPData {
8+
GENERATED_USTRUCT_BODY()
9+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
10+
float float1 = 0.0f;
11+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
12+
float float2 = 0.0f;
13+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
14+
float float3 = 0.0f;
15+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
16+
float float4 = 0.0f;
17+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
18+
float float5 = 0.0f;
19+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
20+
float float6 = 0.0f;
21+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
22+
float float7 = 0.0f;
23+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
24+
float float8 = 0.0f;
25+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
26+
float float9 = 0.0f;
27+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
28+
float float10 = 0.0f;
29+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
30+
float float11 = 0.0f;
31+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
32+
float float12 = 0.0f;
33+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
34+
float float13 = 0.0f;
35+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
36+
float float14 = 0.0f;
37+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
38+
float float15 = 0.0f;
39+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
40+
float float16 = 0.0f;
41+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
42+
float float17 = 0.0f;
43+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
44+
float float18 = 0.0f;
45+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
46+
float float19 = 0.0f;
47+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
48+
float float20 = 0.0f;
49+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
50+
uint8 uint1 = 0;
51+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
52+
uint8 uint2 = 0;
53+
UPROPERTY(EditAnyWhere, BlueprintReadWrite, Category = "UDPCommunication")
54+
uint8 uint3 = 0;
55+
FUDPData() {
56+
}
57+
};
58+
59+
FORCEINLINE FArchive& operator<<(FArchive &Ar, FUDPData &Structure)
60+
{
61+
Ar << Structure.float1;
62+
Ar << Structure.float2;
63+
Ar << Structure.float3;
64+
Ar << Structure.float4;
65+
Ar << Structure.float5;
66+
Ar << Structure.float6;
67+
Ar << Structure.float7;
68+
Ar << Structure.float8;
69+
Ar << Structure.float9;
70+
Ar << Structure.float10;
71+
Ar << Structure.float11;
72+
Ar << Structure.float12;
73+
Ar << Structure.float13;
74+
Ar << Structure.float14;
75+
Ar << Structure.float15;
76+
Ar << Structure.float16;
77+
Ar << Structure.float17;
78+
Ar << Structure.float18;
79+
Ar << Structure.float19;
80+
Ar << Structure.float20;
81+
Ar << Structure.uint1;
82+
Ar << Structure.uint2;
83+
Ar << Structure.uint3;
84+
return Ar;
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include "GameFramework/Actor.h"
4+
#include "Networking.h"
5+
#include "UDPData.h"
6+
#include "UDPReceiver.generated.h"
7+
8+
UCLASS()
9+
class UDPCOMMUNICATION_API AUDPReceiver : public AActor
10+
{
11+
GENERATED_UCLASS_BODY()
12+
public:
13+
FUDPData MyData;
14+
bool UpdateInterest = true;
15+
bool got_new_data = false;
16+
17+
public:
18+
UFUNCTION(BlueprintImplementableEvent, Category = "UDPCommunication")
19+
void BPEvent_DataReceived(const FUDPData& data);
20+
public:
21+
22+
FSocket* ListenSocket;
23+
FUdpSocketReceiver* Receiver = nullptr;
24+
void Recv(const FArrayReaderPtr& ArrayReaderPtr, const FIPv4Endpoint& EndPt);
25+
virtual void Archive(const FArrayReaderPtr & ArrayReaderPtr);
26+
virtual void UpdateReceiverData(FUDPData data);
27+
28+
UFUNCTION(BlueprintCallable, Category = "UDPCommunication")
29+
FUDPData GetData();
30+
31+
UFUNCTION(BlueprintCallable, Category = "UDPCommunication")
32+
bool IsNewDataReady();
33+
34+
UFUNCTION(BlueprintCallable, Category = "UDPCommunication")
35+
bool StartUDPReceiver(const FString& SocketName,
36+
const int32 Port);
37+
38+
public:
39+
40+
/** Called whenever this actor is being removed from a level */
41+
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
42+
43+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include "Serialization/Archive.h"
4+
#include "UDPData.h"
5+
#include "Networking.h"
6+
#include "GameFramework/Actor.h"
7+
#include "UDPSender.generated.h"
8+
9+
UCLASS()
10+
class UDPCOMMUNICATION_API AUDPSender : public AActor
11+
{
12+
GENERATED_UCLASS_BODY()
13+
14+
public:
15+
TSharedPtr<FInternetAddr> RemoteAddr;
16+
FSocket* SenderSocket;
17+
18+
//Tekitab saatja jaoks sokli pordi ja ip-ga
19+
UFUNCTION(BlueprintCallable, Category = "UDPCommunication")
20+
bool StartUDPSender(
21+
const FString& SocketName,
22+
const FString& TheIP,
23+
const int32 ThePort
24+
);
25+
26+
//Saadab numbrite jada läbi saatja ning serialiseerimise
27+
UFUNCTION(BlueprintCallable, Category = "UDPCommunication")
28+
bool UDPSendArray(FUDPData data);
29+
30+
public:
31+
32+
/** Called whenever this actor is being removed from a level */
33+
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
34+
35+
}
36+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Epic Games, Inc. All Rights Reserved.
2+
3+
#include "UDPCommunication.h"
4+
5+
#define LOCTEXT_NAMESPACE "FUDPCommunicationModule"
6+
7+
void FUDPCommunicationModule::StartupModule()
8+
{
9+
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
10+
}
11+
12+
void FUDPCommunicationModule::ShutdownModule()
13+
{
14+
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
15+
// we call this function before unloading the module.
16+
}
17+
18+
#undef LOCTEXT_NAMESPACE
19+
20+
IMPLEMENT_MODULE(FUDPCommunicationModule, UDPCommunication)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright Epic Games, Inc. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "CoreMinimal.h"
6+
#include "Modules/ModuleManager.h"
7+
8+
class FUDPCommunicationModule : public IModuleInterface
9+
{
10+
public:
11+
12+
/** IModuleInterface implementation */
13+
virtual void StartupModule() override;
14+
virtual void ShutdownModule() override;
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "UDPReceiver.h"
2+
3+
AUDPReceiver::AUDPReceiver(const FObjectInitializer& ObjectInitializer)
4+
: Super(ObjectInitializer)
5+
{
6+
ListenSocket = NULL;
7+
}
8+
9+
void AUDPReceiver::Recv(const FArrayReaderPtr & ArrayReaderPtr, const FIPv4Endpoint & EndPt)
10+
{
11+
if (!&ArrayReaderPtr) {
12+
UE_LOG(LogTemp, Warning, TEXT("Cannot read array, nullptr returned."));
13+
return;
14+
}
15+
16+
got_new_data = true;
17+
18+
if (UpdateInterest)
19+
Archive(ArrayReaderPtr);
20+
}
21+
22+
bool AUDPReceiver::StartUDPReceiver(const FString & SocketName, const int32 Port)
23+
{
24+
FIPv4Endpoint Endpoint(FIPv4Address::Any, Port);
25+
int32 BufferSize = 2 * 1024 * 1024;
26+
ListenSocket = FUdpSocketBuilder(*SocketName).AsNonBlocking()
27+
.AsReusable()
28+
.BoundToEndpoint(Endpoint)
29+
.WithReceiveBufferSize(BufferSize);
30+
31+
FTimespan ThreadWaitTime = FTimespan::FromMilliseconds(100);
32+
Receiver = new FUdpSocketReceiver(ListenSocket, ThreadWaitTime, TEXT("UDP Receiver"));
33+
Receiver->OnDataReceived().BindUObject(this, &AUDPReceiver::Recv);
34+
Receiver->Start();
35+
return true;
36+
}
37+
38+
void AUDPReceiver::EndPlay(const EEndPlayReason::Type EndPlayReason)
39+
{
40+
Super::EndPlay(EndPlayReason);
41+
42+
delete Receiver;
43+
Receiver = nullptr;
44+
45+
//Clear all sockets
46+
if (ListenSocket)
47+
{
48+
ListenSocket->Close();
49+
ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(ListenSocket);
50+
}
51+
}
52+
53+
void AUDPReceiver::Archive(const FArrayReaderPtr & ArrayReaderPtr) {
54+
55+
FUDPData data;
56+
*ArrayReaderPtr << data;
57+
58+
//Class Parameter Update function to set object ready for a query from blueprint
59+
UpdateReceiverData(data);
60+
}
61+
62+
void AUDPReceiver::UpdateReceiverData(FUDPData data)
63+
{
64+
MyData = data;
65+
}
66+
67+
FUDPData AUDPReceiver::GetData()
68+
{
69+
UpdateInterest = true; // Ready for new data
70+
got_new_data = false;
71+
return MyData;
72+
}
73+
74+
bool AUDPReceiver::IsNewDataReady() {
75+
return got_new_data;
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "UDPSender.h"
2+
3+
// Sets default values
4+
AUDPSender::AUDPSender(const FObjectInitializer& ObjectInitializer)
5+
: Super(ObjectInitializer)
6+
7+
{
8+
SenderSocket = NULL;
9+
}
10+
11+
bool AUDPSender::StartUDPSender(const FString & SocketName, const FString & TheIP, const int32 ThePort)
12+
{
13+
//Create Remote Address
14+
RemoteAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
15+
16+
bool bIsValid;
17+
RemoteAddr->SetIp(*TheIP, bIsValid);
18+
RemoteAddr->SetPort(ThePort);
19+
20+
if (!bIsValid)
21+
{
22+
UE_LOG(LogTemp, Warning, TEXT("Wrong IP address supplied."));
23+
return false;
24+
}
25+
26+
SenderSocket = FUdpSocketBuilder(*SocketName)
27+
.AsReusable()
28+
.WithBroadcast()
29+
;
30+
31+
//Set Send Buffer Size
32+
int32 SendSize = 2 * 1024 * 1024;
33+
SenderSocket->SetSendBufferSize(SendSize, SendSize);
34+
SenderSocket->SetReceiveBufferSize(SendSize, SendSize);
35+
SenderSocket->SetBroadcast(true);
36+
37+
return true;
38+
}
39+
40+
bool AUDPSender::UDPSendArray(FUDPData data)
41+
{
42+
if (!SenderSocket)
43+
{
44+
UE_LOG(LogTemp, Log, TEXT("There is no socket."));
45+
return false;
46+
}
47+
int32 BytesSent = 0;
48+
49+
FArrayWriter Writer;
50+
Writer << data;
51+
SenderSocket->SendTo(Writer.GetData(), Writer.Num(), BytesSent, *RemoteAddr);
52+
53+
if (BytesSent <= 0) {
54+
UE_LOG(LogTemp, Error, TEXT("Socket exists, but receiver did not accept any packets."));
55+
return false;
56+
}
57+
58+
return true;
59+
}
60+
61+
void AUDPSender::EndPlay(const EEndPlayReason::Type EndPlayReason)
62+
{
63+
Super::EndPlay(EndPlayReason);
64+
65+
if (SenderSocket)
66+
{
67+
SenderSocket->Close();
68+
ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(SenderSocket);
69+
}
70+
}

0 commit comments

Comments
 (0)