# FSocket Connection breaks

**URL:** <https://forums.unrealengine.com/t/fsocket-connection-breaks/326322>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 23, 2015, 7:24pm UTC](https://forums.unrealengine.com/t/fsocket-connection-breaks/326322 "2015-07-23T19:24:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_918f18c7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_918f18c7](https://forums.unrealengine.com/u/anonymous_user_918f18c7)\
**Post date:** [July 23, 2015, 7:24pm UTC](https://forums.unrealengine.com/t/fsocket-connection-breaks/326322/1 "2015-07-23T19:24:20Z")

</div>

I am using an Fsocket to receive data from a remote client. The socket is setup much the same way as in this example:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

I am now only testing over localhost/127.0.0.1 and receiving data from a python script.  
The data is recieved when a user presses a key and the function TCPReceiveData, listed below, is called.

```
TArray<uint8> ANetwork::TCPReceiveData(uint32 BytesToRead)
{
	if (!ConnectionSocket) {
		return TArray<uint8>();
	} else if ( ConnectionSocket == (FSocket*)0xdddddddddddddddd) {
		return TArray<uint8>();
	}
	
	TArray<uint8> ReceivedData;
	FTimespan BlockTime(0, 0, 5); // block wait for 5 secs
	if ( ConnectionSocket->Wait(ESocketWaitConditions::WaitForRead, BlockTime )) {
		ReceivedData.Init(BytesToRead);
		int32 Read = 0;
		ConnectionSocket->Recv(ReceivedData.GetData(), BytesToRead, Read);
	} else {
		return TArray<uint8>();
	}
	
	if (ReceivedData.Num() <= 0) {
		return TArray<uint8>();
	}
	
	return ReceivedData;
}

```

After reading from the socket anywhere between 10 and 50 times the connection breaks and it enters the following if statement:

```
if ( ConnectionSocket == (FSocket*)0xdddddddddddddddd) {
		UE_LOG(LogTemp, Log, TEXT("ConnectionSocket == 0xdddddddd"));
		return TArray<uint8>();
	}

```

And I cannot read from the socket anymore.  
This happens very unregularly and I cannot for the life of me figure out how to solve this

---

<div class="post-metadata">

**Author:** ![qiuwch](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@qiuwch](https://forums.unrealengine.com/u/qiuwch)\
**Post date:** [May 11, 2016, 7:02pm UTC](https://forums.unrealengine.com/t/fsocket-connection-breaks/326322/2 "2016-05-11T19:02:27Z")

</div>

It is possible that your Socket has been GC by the reflection system.
