Socket->Connect is always successful and do not connect

FString YourChosenSocketName(TEXT(“bbbbb”));
FSocket* Socket = FTcpSocketBuilder(*YourChosenSocketName);

    	FString address = TEXT("127.0.0.1");
    	int32 port = 19834;
    	FIPv4Address ip;
    	FIPv4Address::Parse(address, ip);
    
    
    	TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
    	addr->SetIp(ip.Value);
    	addr->SetPort(port);

if(Socket->Connect(*addr))
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString(TEXT("SUCCESS")) );
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString(TEXT("FAILED")) );
}

I do not even have listener on that address and port, and result is always “SUCCESS”, even if i change IP address to any other address.

Any suggestions?

Mhh thats a general Socket thing you can find more info by simply googleing “Socket connect always success” Non blocking you say socket Connect dont wait for response (Don´t block) so it will return true. But you should be able to call GetConnectionState() to get the ESocketConnectionState → Connected, Not_Connected (Pending), Error(basicly refsed connection or something else hit the Fan)

Hope this helps you to understand whats happening.

■■■■ to late with my Answer you figured it out =(

if i make:
FTcpSocketBuilder(*YourChosenSocketName).AsBlocking();
then it seems work as expected.

But i dont understand, why NonBlocking mode connect is successful, and even firewall tells me that “connection is established”, even for IP address that doesnt exist.

It seems, i figured out how to Connect with non-blocking mode, but not sure.

Connect() returns “true”, in non-blocking mode - means “connecting” state, but Socket is still has SCS_Disconnected state internally, it is ok.

Now we wait SCS_Connected or SCS_ConnectionError states. If address is invalid or unavailable then we will get SCS_ConnectionError after some time, otherwise we will get SCS_Connected after some time.

Yes, thats what i thought. Plus, i’ve tested: if i call Socket-Close(), while “connecting” or “connected”, then i will get SCS_ConnectionError. So SCS_ConnectionError is used for any connection interruption, remote, local or by error.

Hi,can you give me a demo about FSocket? I’m really want to know how to use it.,Hi,can you give me a demo about FSocket? I’m really want to know how to use it