UDP sender socket stops working after 1 minute

I’m trying to create a sender/receive system with sockets and UDP, but with (almost) no luck.

I managed to make it working this way: there is a sender and there is a receiver. The sender sends data at each Tick, the receiver does something with it. I used as reference Rama’stutorial.

It works as expected, but after EXACTLY 1 the sender’s client crashes. It’s always 1 minute. I’ve no idea why. I know it has nothing to do with the data I’m sending (I always send the same thing, just for debug purposes)…

After 1 minute it crashes when the sender’s client calls the socket’s SendTo() method. Each time I print to the log this things (the socket’s reference and whether it’s null or not), to understand what’s happening:



UE_LOG(LogTemp,Error,TEXT("socket: %d; is null: %d"), mSenderSocket, mSenderSocket == nullptr);


This is the first print out I get in the log:

[2017.11.11-16.00.20:302][593]LogTemp:Error: socket: 1345165696; is null: 0

As expected, the reference is a “random one” and it’s not null.

It goes like this for almost a minute, printing always the same thing. After 1 minute, this is what it prints:

[2017.11.11-16.01.27:901][317]LogTemp:Error: socket: -572662307; is null: 0

Notice that the reference has changed, but it’s not considered null.

Then it crashes, giving me this in the log:



Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffff


My code is the same as Rama’s code, I’m not doing anything different. I’ve no idea why the socket changes address on its own though… I’m lost, can anyone help me out?

“It works as expected, but after EXACTLY 1 the sender’s client crashes. It’s always 1 minute. I’ve no idea why.”

Sounds like Garbage collection to me, are you sure the actor/object running the socket code is not getting GC’ed?

You could test by changing the Garbage Collection Interval via the Editor

Make sure all Actors and UObjects you are using are UPROPERTY() protected?

:slight_smile:

Rama

You’re right Rama! I didn’t think it was garbage collection because the pointer didn’t point to nullptr, and also didn’t know about this 60 seconds timer. I tried changing the interval like you said and it changed the time the socket was killed.

Turns out the instance of the UObject-derived class that handled the socket wasn’t covered by the UPROPERTY(), and that was the cause of the problem.

By the way, thanks for all the great tutorials Rama, they really help me a lot! :slight_smile:

You’re welcome! And I am glad you got it all figured out now!

:heart:

Rama