Hey Everyone !
I have two problems with the FSocket class, i don’t know if they are related:
-
The GetConnectionState function does not seem too reliable.
-
The Send function needs a call to GetConnectionState to work properly.
Here how it goes.
In order to share pictures (picked up on the hard drive) between server and clients i have written a small file server.
When using the following code:
ESocketConnectionState SocketState = Socket->GetConnectionState();
bool SendOK = Socket->Send(FullMessage.GetData(), FullMessage.Num(), MessageSent);
// Debug
if (SocketState == ESocketConnectionState::SCS_Connected) GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("SCS_Connected"));
if (SocketState == ESocketConnectionState::SCS_NotConnected) GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("SCS_NotConnected"));
GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("FullMessage.Num:" + FString::FromInt(FullMessage.Num())));
GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("MessageSent:" + FString::FromInt(MessageSent)));
I get this output (look only the blue lines):
Notice that the state is SCS_NotConnected, yet the message is fully sent ( MessageSent == FullMessage.Num()). That’s the first problem.
Now, when using the following code:
//ESocketConnectionState SocketState = Socket->GetConnectionState();
bool SendOK = Socket->Send(FullMessage.GetData(), FullMessage.Num(), MessageSent);
// Debug
//if (SocketState == ESocketConnectionState::SCS_Connected) GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("SCS_Connected"));
//if (SocketState == ESocketConnectionState::SCS_NotConnected) GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("SCS_NotConnected"));
GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("FullMessage.Num:" + FString::FromInt(FullMessage.Num())));
GEngine->AddOnScreenDebugMessage(-1, InfoDisplayTime, FColor::Blue, TEXT("MessageSent:" + FString::FromInt(MessageSent)));
I get this output:
You can see that the message has not been sent (MessageSent = -1). And yet all i’ve done is silencing the call to GetConnectionState(). That’s the second problem.
It’s fairly reproducible: as long as i don’t call GetConnectionState() right before the Send, the Send never works. As soon as i add it, it works often but not always (which might be due to some slow/unreliable network: i’m doing this over the internet).
Am i using those functions incorrectly or is there a problem with them ?
Thanks !