# C++ code doesn't execute past a certain point

**URL:** <https://forums.unrealengine.com/t/c-code-doesnt-execute-past-a-certain-point/431498>\
**Category:** C++\
**Tags:** udp, threads, connection, unreal-engine, question, CPP\
**Created:** [August 12, 2018, 3:54pm UTC](https://forums.unrealengine.com/t/c-code-doesnt-execute-past-a-certain-point/431498 "2018-08-12T15:54:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dovlahkin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dovlahkin](https://forums.unrealengine.com/u/Dovlahkin)\
**Post date:** [August 12, 2018, 3:54pm UTC](https://forums.unrealengine.com/t/c-code-doesnt-execute-past-a-certain-point/431498/1 "2018-08-12T15:54:47Z")

</div>

Hi! I’ve been trying to make an UDP connection for receiving and sending data following [Rama’s tutorial](https://wiki.unrealengine.com/UDP_Socket_Sender_Receiver_From_One_UE4_Instance_To_Another); and I’ve managed to do it mostly, except for when it comes to closing connections.

I initialize listen socket like this:

```
bool AUDPConnector::StartUDPReceiver(
	const FString& YourChosenSocketName,
	const FString& TheIP,
	const int32 ThePort
)
{
	FIPv4Address Addr;
	FIPv4Address::Parse(TheIP, Addr);

	//Create Socket
	FIPv4Endpoint Endpoint(Addr, ThePort);

	//BUFFER SIZE
	int32 BufferSize = 2 * 1024 * 1024;

	ListenSocket = FUdpSocketBuilder(*YourChosenSocketName).AsNonBlocking().AsReusable().BoundToEndpoint(Endpoint).WithReceiveBufferSize(BufferSize);

	FTimespan ThreadWaitTime = FTimespan::FromMilliseconds(100);
	UDPReceiver = new FUdpSocketReceiver(ListenSocket, ThreadWaitTime, TEXT("UDP RECEIVER"));
	UDPReceiver->OnDataReceived().BindUObject(this, &AUDPConnector::Recv);
	UDPReceiver->Start();

	return true;
}

```

My code for closing the connection looks like this:

```
void AUDPConnector::CloseConnections()
{
	if (UDPReceiver != nullptr)
	{
		delete UDPReceiver;
		UDPReceiver = nullptr;
	}

	if (ListenSocket)
	{
		ListenSocket->Close();
		ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(ListenSocket);
	}

	if (SenderSocket)
	{
		SenderSocket->Close();
		ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(SenderSocket);
	}
}

```

For some reason the code doesn’t execute past delete UDPReceiver line, so sockets aren’t closed and UDPReceiver isn’t null and it causes unreal to hang when I “close” the connection. I’ve been stuck on this for couple of hours now and I’m totally lost on what to make of it. Halp?

---

<div class="post-metadata">

**Author:** ![Sveitar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sveitar/32/710746_2.png) [@Sveitar](https://forums.unrealengine.com/u/Sveitar)\
**Post date:** [August 13, 2018, 9:51am UTC](https://forums.unrealengine.com/t/c-code-doesnt-execute-past-a-certain-point/431498/2 "2018-08-13T09:51:35Z")

</div>

I you’re using breakpoints to see whether a line of code is being executed make sure you are running Debug configuration instead of development as with development configuration compiler optimizations may trick the debugger.
