void ABP_LevelGameMode::BeginPlay()
{
Super::BeginPlay();
MyWorld = GetWorld();
if (MyWorld)
{
TFuture<void> Future1 = Async(EAsyncExecution::Thread, [&]() {
MyWorld->SpawnActor<AMyEntiyBase>(FVector(0, 0, 0), FRotator(0, 0, 0));
int MsgLen = sizeof(AllEntityInfo);
SOCKET sockSrv = socket(AF_INET, SOCK_DGRAM, 0);
SOCKADDR_IN addrSrv;
std::string ip = "192.168.1.115";
addrSrv.sin_addr.S_un.S_addr = inet_addr(ip.c_str());
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(6001);
bind(sockSrv, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
SOCKADDR_IN addrClient;
char* recvBuf = (char*)malloc(MsgLen);
AllEntityInfo* data = (AllEntityInfo*)malloc(MsgLen);
int msgLen = 0;
while (1)
{
msgLen = recvfrom(sockSrv, recvBuf, MsgLen, 0, (SOCKADDR*)&addrClient, &SOCKADDRLEN);
if (msgLen > 0)
{
memcpy(data, recvBuf, MsgLen);
if (MyWorld)
{
MyWorld->SpawnActor<AMyEntiyBase>(AMyEntiyBase::StaticClass(), FVector(0, 0, 0), FRotator(0, 0, 0));
UE_LOG(LogTemp, Log, TEXT("%d"), data->m_AllEntityInfo[0].ID);
}
}
}
});
}
}