How can I check socket state?

Maybe it will be useful

Maybe looks strange, but works (at least in windows)

{

FSocket* m_Socket;

TArray ReceivedData;

uint32 Size;

while (m_Socket->HasPendingData(Size))

{

int32 Read = 0;

m_Socket->Recv(ReceivedData.GetData(), ReceivedData.Num(), Read);

}

bool HasPendingConnection = false;

bool Res = m_Socket->HasPendingConnection(HasPendingConnection);

}

in case has connection : Res == true & HasPendingConnection == FALSE

in case hasn’t connection : Res == true & HasPendingConnection == TRUE

important: call HasPendingConnection() after Recv()

2 Likes