Hi. The problem is this. The server sends a response. But I don’t understand how to accept it in c++. Can you tell me how to do this?
Code for sending the message to the server. What do I need to add to get a response from the server?
#include "TCPSocketFunction.h"
#include "Networking.h"
#include "Sockets.h"
#include "SocketTypes.h"
#include "SocketSubsystem.h"
#include <Engine.h>
bool UTCPSocketFunction::SendMessage(const FString Message)
{
FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("TCP_TEST"), false);
FString address = TEXT("127.0.0.1");
FIPv4Address ip;
FIPv4Address::Parse(address, ip);
TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
addr->SetIp(ip.Value);
addr->SetPort(2021);
bool connected = Socket->Connect(*addr);
if (connected)
{
FString serialized = Message;
TCHAR* serialuzedChar = serialized.GetCharArray().GetData();
int32 size = FCString::Strlen(serialuzedChar);
int32 sent = 0;
bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serialuzedChar), size, sent);
if (successful)
{
return true;
}
return false;
}
return false;
}