# UE4 Sockets HasPendingData() false before data is finished

**URL:** <https://forums.unrealengine.com/t/ue4-sockets-haspendingdata-false-before-data-is-finished/395367>\
**Category:** Multiplayer & Networking\
**Tags:** Networking, socket, fsocket, unreal-engine, question, CPP\
**Created:** [June 2, 2017, 10:27pm UTC](https://forums.unrealengine.com/t/ue4-sockets-haspendingdata-false-before-data-is-finished/395367 "2017-06-02T22:27:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_24a545b8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24a545b8](https://forums.unrealengine.com/u/anonymous_user_24a545b8)\
**Post date:** [June 2, 2017, 10:27pm UTC](https://forums.unrealengine.com/t/ue4-sockets-haspendingdata-false-before-data-is-finished/395367/1 "2017-06-02T22:27:03Z")

</div>

I have been using the Unreal FSocket to send and receive data. For some reason I’ve never been able to get valid behavior from `socket->HasPendingData()`. Even when I gather data from `socket->Recv()` the `HasPendingData()` has been false.

My hacky workaround was to stop receiving data when I’ve read `0` from `socket->Recv()`, but this fails for larger sets of data (over 1mb)’

Any ideas on how to get the socket interface to operate correctly?

Here is some example code of what I’m doing.

```
 // in init
    mListener = new FTcpListener(FIPv4Endpoint(internetAddress));
    mListener->OnConnectionAccepted().BindRaw(this, &LocalNetworking::handleIncomingConnection);

    bool LocalNetworking::handleIncomingConnection(FSocket* socket, const FIPv4Endpoint& clientEndpoint)
    { 
	
		TArray<TArray<uint8>> receivedData;
	const int32 recvSize = 8192;
	
	int32 lastRead = 0;
	int32 totalRead = 0;

	//blocking wait to help ensure we don't drop data
	socket->Wait(ESocketWaitConditions::WaitForRead, FTimespan::FromSeconds(5));
	// read will 0 out when finished with data...
	uint32 read = 0;
	//while (read !=0)
	while (socket->HasPendingData(read))
	{
		int32 received = 0;
		TArray<uint8> partialData;
		partialData.Init(0, recvSize);
		socket->Recv(partialData.GetData(), partialData.Num(), received);
 
		totalRead += received;
		if (read > 0)
			if (received < recvSize)
				partialData.Shrink();
			receivedData.Add(partialData);
	}
	

	// consolidate all the chunks of data into one string
	FString data;
	for (auto& partial : receivedData)
	{
		// maybe a better way to do this?
		const std::string cstr(reinterpret_cast<const char*>(partial.GetData()), partial.Num());
		data += FString(cstr.c_str());
	}

    }

```

When processing data, I typically receive around 10000 - 15000 bytes ( out of 1mb) before `HasPendingData()` return false.
