I need to send large data chunks from server to clients using sockets.
I connect to server using Online Subsystem (using blueprint nodes Create Session, Find Sessions and Join Session). I connect through LAN and it works.
To receive client IP, I just overrided PreLogin and PostLogin methods of GameModeBase but to connect using sockets I need to know IP of server on clients. I think it is keeped somewhere but I don’t understand where.
To achieve this you need to override PlayerControllers BeginPlay
Look code below:
void AMyPlayerController::BeginPlay()
{
if (NetConnection) // This is a field of PlayerController
{
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Net request url is %s"), *NetConnection->URL.Host));
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("NetConnection is null")));
}
}
This method runs on both client and server for each client on loading of level. On server NetConnection value is null, on client it is not and it contains IP in URL.Host.
Can also use this, will work with steam and steam dedicated.
If its a non dedicated game you may have to append the port after it like, steam.1234557::7777