Hello, everybody.
I would like to create and run simple plugin to receive data from android device used as tcp client and receive it inside of unreal engine plugin, I was able to create tcp listener, but since there is very little documentation, and I am new to unreal engine, and also c++, and also to networking communication. Android application is sending data, i was able to check it with socket test. I was also trying to follow 's tutorial on tcp listener, however I was still not able to receive any data with my plugin.
here is code sample i used:
UE_LOG(LogTemp, Warning, TEXT("Connector Plugin Module loaded!"));
FIPv4Address ip;
const std::string server_ip = "127.0.0.1";
int port = 8888;
if (!FIPv4Address::Parse(UTF8_TO_TCHAR(server_ip.c_str()), ip))
{
UE_LOG(LogTemp, Warning, TEXT(" FIPv4Address::Parse error!"));
}
TSharedRef<FInternetAddr> Addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
Addr->SetIp( ip.Value );
Addr->SetPort( port );
FSocket* listenerSocket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"));
if (!listenerSocket)
{
UE_LOG(LogTemp, Warning, TEXT("Error create socket!"));
}
//FIPv4Endpoint Endpoint = FIPv4Endpoint(ip, port);
FTcpListener myListener = FTcpListener(*listenerSocket, FTimespan(0, 0, 30));
uint32 size;
while(true)
{
if(!listenerSocket->HasPendingData(size) ){
UE_LOG(LogTemp, Warning, TEXT("No Data waiting!"));
}
uint8 Data[1000];
int32 BytesRead;
if (!listenerSocket->Recv(Data, sizeof(Data), BytesRead))
{
UE_LOG(LogTemp, Warning, TEXT("Error recv!"));
}
else {
UE_LOG(LogTemp, Warning, TEXT("OK recv!"));
}
}
if you have any working solution, give me some advice advice, i know i am doing something ( or maybe everything) wrong, but i tried so many solutions.