Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
-add basic comments
-remove extra code
-remove thread stat group warning via unique names for threads
  • Loading branch information
getnamo committed Apr 12, 2018
1 parent 0582c7f commit 3926835
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
11 changes: 3 additions & 8 deletions Source/UDPWrapper/Private/UDPComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "LambdaRunnable.h"
#include "Async.h"
#include "Runtime/Sockets/Public/SocketSubsystem.h"
#include "Runtime/Engine/Classes/Kismet/KismetSystemLibrary.h"

UUDPComponent::UUDPComponent(const FObjectInitializer &init) : UActorComponent(init)
{
Expand Down Expand Up @@ -58,16 +59,10 @@ void UUDPComponent::StartReceiveSocketListening(const int32 InListenPort /*= 300
.AsReusable()
.BoundToEndpoint(Endpoint)
.WithReceiveBufferSize(BufferSize);

/* doesn't work...
RemoteAdress = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
bool bIsValid;
RemoteAdress->SetIp(TEXT("0.0.0.0"), bIsValid);
RemoteAdress->SetPort(InListenPort);
ReceiverSocket->Bind(*RemoteAdress);*/

FTimespan ThreadWaitTime = FTimespan::FromMilliseconds(100);
UDPReceiver = new FUdpSocketReceiver(ReceiverSocket, ThreadWaitTime, TEXT("UDP RECEIVER"));
FString ThreadName = FString::Printf(TEXT("UDP RECEIVER-%s"), *UKismetSystemLibrary::GetDisplayName(this));
UDPReceiver = new FUdpSocketReceiver(ReceiverSocket, ThreadWaitTime, *ThreadName);

UDPReceiver->OnDataReceived().BindUObject(this, &UUDPComponent::OnDataReceivedDelegate);
OnReceiveSocketStartedListening.Broadcast();
Expand Down
30 changes: 15 additions & 15 deletions Source/UDPWrapper/Public/UDPComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ class UDPWRAPPER_API UUDPComponent : public UActorComponent
UPROPERTY(BlueprintAssignable, Category = "UDP Events")
FUDPMessageSignature OnReceivedBytes;

/** Callback when we start listening */
/** Callback when we start listening on the udp receive socket*/
UPROPERTY(BlueprintAssignable, Category = "UDP Events")
FUDPEventSignature OnReceiveSocketStartedListening;

/** Called after receiving socket has been closed. */
UPROPERTY(BlueprintAssignable, Category = "UDP Events")
FUDPEventSignature OnReceiveSocketStoppedListening;


/** Default connection IP string in form e.g. 127.0.0.1. */
/** Default sending socket IP string in form e.g. 127.0.0.1. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UDP Connection Properties")
FString SendIP;

Expand Down Expand Up @@ -69,34 +68,35 @@ class UDPWRAPPER_API UUDPComponent : public UActorComponent

/**
* Connect to a udp endpoint, optional method if auto-connect is set to true.
* Emit function will then work as long the network is reachable. By default
* it will attempt this setup for this socket on beginplay.
*
* @param AddressAndPort the address in URL format with port
*
* @param InIP the ip4 you wish to connect to
* @param InPort the udp port you wish to connect to
*/
UFUNCTION(BlueprintCallable, Category = "UDP Functions")
void ConnectToSendSocket(const FString& InIP = TEXT("127.0.0.1"), const int32 InPort = 3000);

/**
* Close the sending socket. This is usually automatically done on endplay.
*/
UFUNCTION(BlueprintCallable, Category = "UDP Functions")
void CloseSendSocket();

/**
* Start listening at given port for udp messages. Will auto-listen on begin play by default
*/
UFUNCTION(BlueprintCallable, Category = "UDP Functions")
void StartReceiveSocketListening(const int32 InListenPort = 3002);

UFUNCTION(BlueprintCallable, Category = "UDP Functions")
void CloseReceiveSocket();

/**
* Close the sending socket
* Close the receiving socket. This is usually automatically done on endplay.
*/
UFUNCTION(BlueprintCallable, Category = "UDP Functions")
void CloseSendSocket();

//
//Blueprint Functions
//
void CloseReceiveSocket();

/**
* Emit bytes to the udp channel.
* Emit specified bytes to the udp channel.
*
* @param Message Bytes
*/
Expand Down

0 comments on commit 3926835

Please sign in to comment.