TestActor.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Kismet/BlueprintFunctionLibrary.h"
  5. #include "HAL/Runnable.h"
  6. #include "IPAddress.h"
  7. #include "Sockets.h"
  8. #include "TestActor.generated.h"
  9. //class FSocket;
  10. class FRunnableThread;
  11. /**
  12. * Helper class inhibiting screen saver by e.g. moving the mouse by 0 pixels every 50 seconds.
  13. */
  14. class FSocketListener : public FRunnable
  15. {
  16. public:
  17. FSocketListener(FInternetAddr* InAddr)
  18. : bEnabled(true), Addr(InAddr)
  19. {}
  20. protected:
  21. bool Init() override;
  22. void Stop() override
  23. {
  24. bEnabled = false;
  25. FPlatformMisc::MemoryBarrier();
  26. }
  27. uint32 Run() override;
  28. void InitSocket();
  29. bool AcceptClient();
  30. void ProcessClientData();
  31. protected:
  32. FInternetAddr* Addr = nullptr;
  33. FSocket* Socket = nullptr;
  34. FSocket* ClientSocket = nullptr;
  35. bool bEnabled = true;
  36. };
  37. UCLASS(BlueprintType)
  38. class EMPTY53_API ATestActor : public AActor
  39. {
  40. GENERATED_BODY()
  41. public:
  42. UFUNCTION(BlueprintCallable)
  43. bool BeginConnect();
  44. UFUNCTION(BlueprintCallable)
  45. bool SendMessage(const FString& Msg);
  46. public:
  47. virtual void BeginPlay() override;
  48. virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
  49. public:
  50. UPROPERTY(BlueprintReadWrite, EditAnywhere)
  51. FString Ip;
  52. UPROPERTY(BlueprintReadWrite, EditAnywhere)
  53. int32 Port;
  54. FSocket* Host;
  55. TSharedPtr<FInternetAddr> Addr;
  56. FRunnableThread* Thread = nullptr;
  57. };