Guest User

ConnectionToPy.cpp

a guest
Nov 18th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "RandoVirtuel.h"
  4. #include "ConnectionToPy.h"
  5. #include <sys/socket.h>
  6.  
  7. // Sets default values
  8. AConnectionToPy::AConnectionToPy()
  9. {
  10. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
  11. PrimaryActorTick.bCanEverTick = true;
  12.  
  13. }
  14.  
  15. // Called when the game starts or when spawned
  16. void AConnectionToPy::BeginPlay()
  17. {
  18. Super::BeginPlay();
  19. FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
  20. FString address = TEXT("127.0.0.1");
  21. int32 port = 8000;
  22. FIPv4Address ip;
  23. FIPv4Address::Parse(address, ip);
  24.  
  25.  
  26. TSharedRef addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
  27. addr->SetIp(ip.GetValue());
  28. addr->SetPort(port);
  29. bool connected = Socket->Connect(*addr);
  30. }
  31.  
  32. // Called every frame
  33. void AConnectionToPy::Tick( float DeltaTime )
  34. {
  35. Super::Tick( DeltaTime );
  36. FString serialized = TEXT("loadPlayer|1");
  37. TCHAR *serializedChar = serialized.GetCharArray().GetData();
  38. int32 size = FCString::Strlen(serializedChar);
  39. int32 sent = 0;
  40. bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent);
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment