# FSocket-\>Recv no data response

**URL:** <https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977>\
**Category:** Multiplayer & Networking\
**Tags:** Networking, fsocket, unreal-engine, UE4, question, CPP\
**Created:** [October 23, 2014, 2:22am UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977 "2014-10-23T02:22:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![StewVanB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@StewVanB](https://forums.unrealengine.com/u/StewVanB)\
**Post date:** [October 23, 2014, 2:22am UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/1 "2014-10-23T02:22:35Z")

</div>

I have gathered as much data as I could find in the documentation as well as around the web on UE4’s socket networking ability. I have successfully connected to a server and sent data. The server echos the sent data back to the client. However, FSocket-\>Recv(blah, blah, blah) isn’t reading any data back from the server. I have another client written in C# that does receive the data echo.

```
void ANetwork_Test::TestTransmit(FString outData){
	
	// Stores the final server IP.
	FIPv4Address serverIP;
	// The ip address of the serverList Server.
	FString serverIpAddress = "192.168.1.11"; 
	// Port for connection to the serverList Server.
	int32 serverListPort = 24575;
	// Turn the string Ip into a usable ip and store it in serverIP.
	FIPv4Address::Parse(serverIpAddress, serverIP);

	// Create a network socket to connect to the serverList Server.
	sendSock = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("sendSock"), false);

	// Get a socketable internet address for use in the socket.
	TSharedRef < FInternetAddr > intAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();

	// Set the IP and PORT of the new socketable internet address.
	intAddr->SetIp(serverIP.GetValue());
	intAddr->SetPort(serverListPort);

	// Attempt a connection and store result in the connectionAttempt bool.
	bool connectionAttempt = sendSock->Connect(*intAddr);

	if (connectionAttempt){
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Connect attempt SUCCESS!"));
		SendData(sendSock,outData);
	}
	else{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Connect attempt failed."));
		return;
	}
}

```

This is the SendData code:

```
void ANetwork_Test::SendData(FSocket* client, FString data){
	TCHAR *sendData = data.GetCharArray().GetData();
	int32 size = FCString::Strlen(sendData);
	int32 sent = 0;
	uint8 *inData = 0;
	FString inDataString = "NO DATA";
	int32 byteCount = 0;
	uint32 dataSize = 0;

	client->Send((uint8*)TCHAR_TO_UTF8(sendData), size, sent);
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Data away!"));
	client->HasPendingData(dataSize);
	if (dataSize != 0){
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Got something."));
		client->Recv(inData, dataSize, byteCount);
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(byteCount));
	}
}

```

I haven’t been able to get the data back from the server in UE4 but it works in the C# socket client I have.  
Any thoughts?

Thanks,  
-StewVanB

---

<div class="post-metadata">

**Author:** ![ProfessionsQuest\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ProfessionsQuest\_1](https://forums.unrealengine.com/u/ProfessionsQuest_1)\
**Post date:** [October 29, 2014, 8:46pm UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/2 "2014-10-29T20:46:35Z")

</div>

I would be interested in figuring this out as well. 😑 Having this same issue.

---

<div class="post-metadata">

**Author:** ![Moynzy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Moynzy](https://forums.unrealengine.com/u/Moynzy)\
**Post date:** [October 29, 2015, 6:55pm UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/3 "2015-10-29T18:55:34Z")

</div>

Hi, did you find an answer? im able to recieve data from my server, but it prints it as 0.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8e2766aa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8e2766aa](https://forums.unrealengine.com/u/anonymous_user_8e2766aa)\
**Post date:** [November 4, 2015, 4:43pm UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/4 "2015-11-04T16:43:21Z")

</div>

Hello, StewVanB

I am sorry to hear about your problem.

Please note that the common practice in this case is to put your send and response-handling logic in separate functions. This way, you can add a function like this:

```
void ReceiveMessage()
{
    // assuming that variables are initialized correctly
    client->HasPendingData(dataSize);
    if (dataSize != 0){
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Got something."));
      client->Recv(inData, dataSize, byteCount);
      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(byteCount));
    }

```

Now you can call it in timer:

```
 FTimerHandle MyTimerHandle;
 GetWorldTimerManager().SetTimerMyTimerHandle, this, &AMyActor::ReceiveMessage, 0.01, true);

```

Thus, you should get appropriate messages.

Hope this helped!

Have a great day!

---

<div class="post-metadata">

**Author:** ![Moynzy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Moynzy](https://forums.unrealengine.com/u/Moynzy)\
**Post date:** [November 5, 2015, 9:43am UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/5 "2015-11-05T09:43:53Z")

</div>

Hello, I have tested your code in my project, and I am having the same problem as Stew.

Using the send method, my server crashes when it receives data.

Sending data from the server to the client, for example a string of test, prints out as -1.

Have you ever encountered this problem?

---

<div class="post-metadata">

**Author:** ![guo13080319157](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@guo13080319157](https://forums.unrealengine.com/u/guo13080319157)\
**Post date:** [March 29, 2018, 1:29am UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/6 "2018-03-29T01:29:23Z")

</div>

Same problem, again.  
Try the method, Not solved

---

<div class="post-metadata">

**Author:** ![Magesturm](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Magesturm](https://forums.unrealengine.com/u/Magesturm)\
**Post date:** [January 23, 2019, 8:20pm UTC](https://forums.unrealengine.com/t/fsocket-recv-no-data-response/296977/7 "2019-01-23T20:20:50Z")

</div>

I was having the same problem.

The problem is that the buffer is null. with the changes the bytecount and the dataSize should be the same size.

void HandleRecieve()  
{  
uint32 dataSize = 0;  
client-\>HasPendingData(dataSize);

```
if (dataSize != 0) 
{
	uint8 *inData = new uint8[dataSize];
	int32 byteCount = 0;

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Recieved data from server."));
	socket->Recv(inData, dataSize, byteCount);
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(byteCount));
}

```

}
