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