FSocket lost some data when receive

I am making a multiplayer game

Sever has send multiple rows like following: ( “a~1~2~3|b~3~4~5|a~13~14~15|” )

Sometimes clients can get complete data, sometimes one of them only get incomplete like “a~1~2~3|b~3~4~5|a~13~”.

The length of buffer for reading and sending between client and server are big enough.

I use FSocket in TCP mode

UE 4.23

Server in linux use** Posix socket**


void ACFMapServerMng::ReceiveMessage() {
//I use FSocket
static long long total = 0;
uint32 dataSize = 0;
if (SocketClient && SocketClient->HasPendingData(dataSize)) {

     TArray<uint8> ReceiveData;
     uint32 size = 0;
     uint8 element = 0;
     ReceiveData.Init(element, 4096u);
     int32 read = 0;
     SocketClient->Recv(ReceiveData.GetData(), ReceiveData.Num(), read);
     const FString receivedMessage = FString(ANSI_TO_TCHAR(reinterpret_cast<const char*>(ReceiveData.GetData())));
     FString log = "ReceiveMessage From Server:" + receivedMessage;
     //std::cout << "length of message " << receivedMessage.Len();
     UE_LOG(LogTemp, Warning, TEXT("Length of Message  %d ]"), receivedMessage.Len());
     for (int i = 0; i < mapServerListeners.Num(); i++) {

         UObject* mapListenerObject = mapServerListeners*.GetObject();
         if (mapListenerObject) {

             ICFMapServerListener::Execute_OnMapMessage(mapListenerObject, receivedMessage);
         }
     }
}
}

Anyone met same issue before. Thanks :slight_smile: