But i always obtain a ipaddress of 0.0.0.0 in the string.
The same problem i have with the RecvFrom function wich contains a pointer to the remote address.
It also returns 0’s all the time
I’m using GetLocalHostAddr for the local IP (the IP that is used to communicate with your router).
here is some sample code:
bool canBind = false;
TSharedRef<FInternetAddr> localIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);
if (localIp->IsValid())
{
GLog->Log(localIp->ToString(false)); // if you want to append the port (true) or not (false).
}
Hi!
How do I set up the includes for this to work with a “launcher” version of Unreal Engine? I get compilation errors with just #include “SocketSubsystem.h”, so I guess I need to setup dependency modules, but I don’t understand how.
It’s been a while since I’ve done this and our networking has changed since then so this might be incorrect… But I think the header file is just “Networking.h” that is a header that includes a bunch of networking headers (sockets, subsystems, ipv4/6, etc). Then in your project’s Build.cs you will need to add the “Networking” module to your “PublicDependencyModuleNames” list.
Works like a charm, thanks! You should upgrade this to an Answer — except I should point out that this always obtains 127.0.0.1 if you run it on Android, which isn’t useful. But it works great on Windows.
Thank you! Works great on Windows. Just a warning for others if you’re developing for Android. It has some weird issue that makes it return 127.0.0.1 no matter what, though. I hope they fix it in the near future. I think it’s related to Issue UE-62267