Connect OnlineBeaconClient in Advanced Steam Session

Hi, I’m using UE 4.27 and Advanced Steam sessions plugin. Server / client connection works perfectly. Now, since I always get ping of 9999, I want to use Online Beacons to connect before player joins.

I have created host beacon using this code in my Game mode. It works normally. Host beacon is created and all is good.

	AOnlineBeaconHost* MainBeaconHost = GetWorld()->SpawnActor<AOnlineBeaconHost>(AOnlineBeaconHost::StaticClass());
	
	if (MainBeaconHost != nullptr && MainBeaconHost->InitHost())
	{
		MainBeaconHost->PauseBeaconRequests(false);
		FragileBeaconHost = GetWorld()->SpawnActor<AFragileOnlineBeaconHostObject>(AFragileOnlineBeaconHostObject::StaticClass());

		if (FragileBeaconHost != nullptr)
		{
			MainBeaconHost->RegisterHost(FragileBeaconHost);
		}
	}

Now, on the client side I have an issue. InitClient of BeaconClient requires FURL. What should I pass to it? Since I’m using steam sessions, and not dedicated server logic, I don’t have IP. Is there anything else I should pass? I have reference to the FOnlineSessionSearchResult, and that’s it.

Any help is appreciated. Thanks in advance.

You should be able to call IOnlineSessionPtr::GetResolvedConnectString https://github.com/EpicGames/UnrealEngine/blob/46544fa5e0aa9e6740c19b44b0628b72e7bbd5ce/Engine/Plugins/Online/OnlineSubsystem/Source/Public/Interfaces/OnlineSessionInterface.h#L890
Pass the FOnlineSessionSearchResult as the first parameter, NAME_BeaconPort as the second. The third will be filled with the connect string that you can pass to FURL.
You may also check the QosBeacon classes which already determines response timing.

5 Likes

Thank you!!! Works flawlessly.

In case anyone needs same thing.

IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get();
SessionInterface = Subsystem->GetSessionInterface();
FString Address;
SessionInterface->GetResolvedConnectString(Result, NAME_BeaconPort, Address);
FURL Destination = FURL(nullptr, *Address, ETravelType::TRAVEL_Absolute);
Destination.Port = 7787;
InitClient(Destination);

And you’re good to go.

3 Likes

Hi, I know it’s been a year, but I have this same problem, and was wondering how you got the online session search result for your beacon?

Well, I got it in a way I showed here as a code. It should work fine for you.

Look at these series, should be enough to help you: Unreal Engine C++ Nazi Zombies: 19: "Beacon: Setup Host Beacon" - YouTube

2 Likes

I am doing something similar to you, using Listen servers with EOS

But my packets are not being replied to by the server. Know what the problem could be? Do we need to open port for this to work?

Hi, Welcome to the the forums ;).

Yes I remember having issues with the port. If you use QoS beacon, it would not work for me because the port was not set. But my custom one worked quite fine with the code provided above. It is hard to blindly like this tell what went wron on your end. Maybe you can show us your output log.

Hello. Thank you for welcoming me.

Let me explain.
I am trying to connect to Listen servers from clients. The reason for using beacons here is that I want to connect, check ping and then disconnect so that I may choose the best server.

My DefaultEngine.ini has the following (only things related to beacon shared):

[/Script/Engine.Engine]
+NetDriverDefinitions=(DefName="BeaconNetDriver",DriverClassName="OnlineSubsystemUtils.IpNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[/Script/OnlineSubsystemUtils.OnlineBeaconHost]
ListenPort=7787
BeaconConnectionInitialTimeout=10.0
BeaconConnectionTimeout=10.0

[/Script/Engine.NetworkSettings]
n.VerifyPeer=False

Following is the ClientBeacon.cpp

#include "Beacon/ClientBeacon.h"

AClientBeacon::AClientBeacon()
{

}

bool AClientBeacon::ConnectToServer(const FString& IP)
{
	currentConnectionIP = IP;
	FURL serverURL = FURL(nullptr, *IP, ETravelType::TRAVEL_Absolute);
	serverURL.Port = 7787;
	return InitClient(serverURL);

}

void AClientBeacon::DisconnectFromServer()
{
	DestroyBeacon();
}

void AClientBeacon::OnFailure()
{
	UE_LOG(LogTemp, Warning, TEXT("Server Connection Failed"));

	ConnectionResponse.Broadcast(false, currentConnectionIP);
}

void AClientBeacon::OnConnected()
{
	UE_LOG(LogTemp, Warning, TEXT("Server Connection Success"));

	ConnectionResponse.Broadcast(true, currentConnectionIP);
}

Following in the server beacon object

// Fill out your copyright notice in the Description page of Project Settings.


#include "Beacon/ServerBeaconObject.h"
#include "Beacon/ClientBeacon.h"

AServerBeaconObject::AServerBeaconObject()
{
	ClientBeaconActorClass = AClientBeacon::StaticClass();
	BeaconTypeName = ClientBeaconActorClass->GetName();
	
}

void AServerBeaconObject::OnClientConnected(AOnlineBeaconClient* NewClientActor, UNetConnection* ClientConnection)
{
	Super::OnClientConnected(NewClientActor, ClientConnection);

	if (NewClientActor)
	{
		UE_LOG(LogTemp, Warning, TEXT("NewClientActor Connected!"));
	}
}

and I spawn the server beacon in game instance using this code:

bool UParentGI::SpawnServerBeacon()
{
	onlineBeaconBase = GetWorld()->SpawnActor<AOnlineBeaconHost>(AOnlineBeaconHost::StaticClass());
	if (onlineBeaconBase)
	{
		if (onlineBeaconBase->InitHost())
		{
			onlineBeaconBase->PauseBeaconRequests(false);

			serverBeacon = GetWorld()->SpawnActor<AServerBeaconObject>(AServerBeaconObject::StaticClass());
			if (serverBeacon)
			{
				onlineBeaconBase->RegisterHost(serverBeacon);
				return true;
			}
		}
	}
	return false;
}

With all of this configuration, I am able to connect when i input localhost IP 127.0.0.1
but when i make my friend run the same project (not build, could that be a reason?) and spawn server beacon while i take the flow that spawn client beacon, and input his IP to connect, i get the following:

[2023-09-06T17:27:16.766Z]LogNet: IpConnection_0 setting maximum channels to: 32767
[2023-09-06T17:27:16.766Z]PacketHandlerLog: Loaded PacketHandler component: Engine.EngineHandlerComponentFactory (StatelessConnectHandlerComponent)
[2023-09-06T17:27:16.772Z]LogHandshake: Stateless Handshake: NetDriverDefinition 'BeaconNetDriver' CachedClientID: 3
[2023-09-06T17:27:16.773Z]LogNet: Game client on port 7787, rate 100000
[2023-09-06T17:27:16.773Z]LogNetVersion: CombatFury 1.1, NetCL: 25360045, EngineNetworkVersion: 32, GameNetworkVersion: 0 (Checksum: 2674908249)
[2023-09-06T17:27:16.773Z]LogBlueprintUserMessages: [PC_Primary_C_0] true
[2023-09-06T17:27:16.778Z]LogNet: UNetDriver::TickDispatch: Very long time between ticks. DeltaTime: 17.16, Realtime: 0.01. NetDriverEIK_0
[2023-09-06T17:27:16.780Z]LogNet: Initial Connect Diagnostics: Sent '0' packets in last '17.159061' seconds, no packets received yet.
[2023-09-06T17:27:27.015Z]LogNet: Initial Connect Diagnostics: Sent '9' packets in last '10.238510' seconds, no packets received yet.

So it feels like the server is unable to receive packets.
Which is why I am wondering if Online Beacons requires open ports / port forwarding to be done?

I apologize if i just bombarded you with info

Are you using any Online subsystem? I used steam, and my game was approved and created for the Steam. So I already had is prepared. If you don’t have your game on Steam, then this cannot work.

To be honest, I don’t remember the details, only thing I recall I copied the logic from QoS Beacon, and removed the port.

This video should help you about it: https://youtu.be/_zPZIn-o9rc

I also use this in my DefaultEngine.ini
+NetDriverDefinitions=(DefName="BeaconNetDriver",DriverClassName="/Script/OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="/Script/OnlineSubsystemUtils.IpNetDriver")