Advertisement
Guest User

Untitled

a guest
Feb 24th, 2015
35
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "Testspel.h"
  4. #include "GameServer.h"
  5.  
  6.  
  7. bool UGameServer::ConnectToServer(int32 port)
  8. {
  9.  
  10.    
  11.     FString address = TEXT("127.0.0.1");
  12.  
  13.     TSharedRef < FInternetAddr > addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
  14.     FIPv4Address ip;
  15.     FIPv4Address::Parse(address, ip);
  16.  
  17.     addr->SetIp(ip.GetValue());
  18.     addr->SetPort(port);
  19.     //bool connected = Socket->Connect(*addr);
  20.     //Socket->Bind(*addr);
  21.     Socket = FUdpSocketBuilder(TEXT("default"))
  22.         .AsNonBlocking()
  23.         .AsReusable()
  24.         .BoundToAddress(ip)
  25.         .BoundToPort(port);
  26.     if (Socket)
  27.     {
  28.         return true;
  29.     }
  30.     else
  31.     {
  32.         return true;
  33.     }
  34.     return true;
  35. }
  36.  
  37. FString UGameServer::SendMessageToServer()
  38. {
  39.     FString serialized = TEXT("message, hellooo|1");
  40.     TCHAR *serializedChar = serialized.GetCharArray().GetData();
  41.  
  42.     int32 size = FCString::Strlen(serializedChar);
  43.     int32 sent = 0;
  44.     FString returnst = "True";
  45.     if (bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent))
  46.     {
  47.         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Successfully sent to Server!!"));
  48.         return returnst;
  49.     }
  50.     else
  51.     {
  52.         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Failed sending to Server!!"));
  53.         return "False";
  54.     }
  55. }
Advertisement
RAW Paste Data Copied
Advertisement