Download

FSocket Disconnects immediately after connecting

I’ve already asked on the answer hub but I’m not getting any help. I’m trying to play with FSockets so I can craft a basic login system, but I’m really struggling. I wrote the server in C# for simplicity sake, but as soon as the client in UE4 connects it disconnects immediately and I can’t communicate. Heres the client code in UE4:



FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("Default"), false);
FString address = TEXT("192.168.0.100");
int32 port = 9505;
FIPv4Address ip;
FIPv4Address::Parse(address, ip);

TSharedRef<FInternetAddr>addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
addr->SetIp(ip.GetValue());
add->SetPort(port);

bool isConnect = Socket->Connect(*addr);


It returns that it connected ok, but when I check the connection status it isn’t connected at all. The server sees the connection and accepts it, but if I check if it’s connected immediately after accepting the connection it’s not connected any more. Any idea what the hell is going on? I’m so confused. (Also if I check the last error its always no error)

If u are checking if connected using the socket GetConnectionState() method, it will always seem to return Disconnected for some reason. (BUG?)
Just try to send/receive data after u connected the socket.

U can try to track the state manually.

if Connect return true, u are connected.
If Send/Receive return 0 or less bytes, u got disconnected (same like C# socket)