How to check invalid FSocket?

I’m doing network programming,

When the server is shutdown ,

my game also crashed ,

I found that because my socket has become invalid

How to check invalid FSocket?

It seem there really no way to check it, i can find any code that would do that and once pointer is invalid from pointer it self is impossible to determent if it’s valid, thats why it’s very nasty state. So only way to do it is destroy socket yourself when you know connection as been ended and track that information.

But there DestroySocket function in Socket Subsystem which most likely invalids the pointer. Thing is i don’t see it being called inside Socket module so socket can’t invalidate itself (or else i missed something), so are you sure you properly initiate socket before it’s being use and not destroy by anything? also check if actor pointer it self is valid when crash happens, because invalid actor = invalid socket in it.

Okay, thanks, let me give it a try

I solved it

I found that Socket was still trying to receive data when the game was closed

I use Socket-> HasPendingData to determine whether there is data,

If there is no data no longer receive the data

This is my code:

 uint8 recvBuffer[1024];
 uint32 Size;
 while (Socket->HasPendingData(Size))
 {
     int32 read = 0;
     Connected = Socket->Recv(recvBuffer, 4, read);
     ...
 }

=================================================

This is my old code:

 uint8 recvBuffer[1024];
 while (true)
 {
     int32 read = 0;
     Connected = Socket->Recv(recvBuffer, 4, read);
     ...
 }

Thank you.