Hey all,
I have setup a basic multiplayer and I can create and find servers, however, when I join the server, the log shows success but the level does not change to match the host. Currently I am using the NULL subsystem and a listen server.
On the host side, there is an error that the map isn’t listening.
My DefaultEngine.ini is pretty standard from what I’ve gathered…
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
[OnlineSubsystem]
DefaultPlatformService=NULL
[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
GameServerQueryPort=27015
[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
Here’s the create and join code:
// Fill out your copyright notice in the Description page of Project Settings.
#include "SQGameInstance.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
USQGameInstance::USQGameInstance()
{
}
void USQGameInstance::Init()
{
Super::Init();
// get reference to subsystem and bind to delgates
//if (IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get())
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get();
if(Subsystem != nullptr)
{
SessionInterface = Subsystem->GetSessionInterface();
if (SessionInterface.IsValid())
{
SessionInterface->OnCreateSessionCompleteDelegates.AddUObject(this, &USQGameInstance::OnCreateSessionComplete);
SessionInterface->OnFindSessionsCompleteDelegates.AddUObject(this, &USQGameInstance::OnFindSessionComplete);
SessionInterface->OnJoinSessionCompleteDelegates.AddUObject(this, &USQGameInstance::OnJoinSessionComplete);
UE_LOG(LogTemp, Warning, TEXT("Init() Succeeded!"));
}
else
UE_LOG(LogTemp, Warning, TEXT("Init() Failed! Session Interface is NOT valid!"));
}
else
UE_LOG(LogTemp, Warning, TEXT("Init() Failed! Subsystem is nullptr!"));
}
void USQGameInstance::OnCreateSessionComplete(FName SessionName, bool Succeeded)
{
if (Succeeded)
{
GetWorld()->ServerTravel("/Game/Maps/Space?Listen");
UE_LOG(LogTemp, Warning, TEXT("StarQuest Server Created"));
}
else
UE_LOG(LogTemp, Warning, TEXT("Failed to create StarQuest Server"));
}
void USQGameInstance::OnFindSessionComplete(bool Succeeded)
{
if (Succeeded)
{
UE_LOG(LogTemp, Warning, TEXT("StarQuest Finding Servers..."));
TArray<FOnlineSessionSearchResult> SearchResult = SessionSearch->SearchResults;
if (SearchResult.Num())
{
UE_LOG(LogTemp, Warning, TEXT("StarQuest Server Found! Printing Results!"));
UE_LOG(LogTemp, Warning, TEXT("StarQuest Server: %d"), SearchResult.Num());
SessionInterface->JoinSession(0, FName("StarQuest Server"), SearchResult[0]); // hardcoded 0 search for testing
}
else
UE_LOG(LogTemp, Warning, TEXT("No StarQuest Server Found."));
}
else
UE_LOG(LogTemp, Warning, TEXT("Failed to execute search!"));
}
void USQGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if (PlayerController != nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("Joining..."));
FString JoinAddress = "";
SessionInterface->GetResolvedConnectString(SessionName, JoinAddress);
if (JoinAddress != "")
{
PlayerController->ClientTravel(JoinAddress, ETravelType::TRAVEL_Absolute);
UE_LOG(LogTemp, Warning, TEXT("Joined StarQuest Server: %s"), *FString(JoinAddress));
}
else
UE_LOG(LogTemp, Warning, TEXT("Failed to join StarQuest Server: %s"), *FString(JoinAddress));
}
else
UE_LOG(LogTemp, Warning, TEXT("Failed to get Local PlayerController"));
}
void USQGameInstance::CreateServer()
{
UE_LOG(LogTemp, Warning, TEXT("Create Server"));
FOnlineSessionSettings SessionSettings;
SessionSettings.bAllowJoinInProgress = true;
SessionSettings.bIsDedicated = false;
SessionSettings.bIsLANMatch = true;//(IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSettings.bShouldAdvertise = true;
SessionSettings.bUsesPresence = true;
SessionSettings.bUseLobbiesIfAvailable = true;
SessionSettings.NumPublicConnections = 30; // max planets/players but might change
SessionInterface->CreateSession(0, FName("StarQuest Server"), SessionSettings);
}
void USQGameInstance::JoinServer()
{
SessionSearch = MakeShareable(new FOnlineSessionSearch());
SessionSearch->bIsLanQuery = true;// (IOnlineSubsystem::Get()->GetSubsystemName() == "NULL");
SessionSearch->MaxSearchResults = 10000;
SessionSearch->QuerySettings.Set("SEARCH_PRESENCE", true, EOnlineComparisonOp::Equals);
SessionInterface->FindSessions(0, SessionSearch.ToSharedRef());
}
EDIT:
It looks like I’m having a network failure, though realistically I am testing on the same machine so…
[2023.06.16-21.34.21:208][465]LogLiveCoding: Display: Successfully initialized, removing startup thread
[2023.06.16-21.34.29:069][869]LogTemp: Warning: Primary Action Time: 0.004432
[2023.06.16-21.34.50:786][144]LogTemp: Warning: Primary Action Time: 0.002677
[2023.06.16-21.34.57:778][739]LogTemp: Warning: StarQuest Finding Servers...
[2023.06.16-21.34.57:778][739]LogTemp: Warning: StarQuest Server Found! Printing Results!
[2023.06.16-21.34.57:779][739]LogTemp: Warning: StarQuest Server: 1
[2023.06.16-21.34.57:779][739]LogTemp: Warning: Joining...
[2023.06.16-21.34.57:780][739]LogTemp: Warning: Joined StarQuest Server: 192.168.50.115:0
[2023.06.16-21.34.57:780][739]LogNet: Browse: 192.168.50.115:0/Game/Maps/MainMenu
[2023.06.16-21.34.57:783][739]LogInit: WinSock: Socket queue. Rx: 32768 (config 32768) Tx: 32768 (config 32768)
[2023.06.16-21.34.57:783][739]LogNet: Created socket for bind address: 0.0.0.0:0
[2023.06.16-21.34.57:784][739]LogNet: IpConnection_2147482489 setting maximum channels to: 32767
[2023.06.16-21.34.57:785][739]PacketHandlerLog: Loaded PacketHandler component: Engine.EngineHandlerComponentFactory (StatelessConnectHandlerComponent)
[2023.06.16-21.34.57:808][739]LogHandshake: Stateless Handshake: NetDriverDefinition 'GameNetDriver' CachedClientID: 1
[2023.06.16-21.34.57:809][739]LogNet: Game client on port 0, rate 100000
[2023.06.16-21.34.57:810][739]LogNetVersion: StarQuest 1.0.0.0, NetCL: 0, EngineNetworkVersion: 32, GameNetworkVersion: 0 (Checksum: 1513362930)
[2023.06.16-21.35.07:779][263]LogNet: Initial Connect Diagnostics: Sent '9' packets in last '10.000342' seconds, no packets received yet.
[2023.06.16-21.35.17:781][726]LogNet: Initial Connect Diagnostics: Sent '10' packets in last '10.001527' seconds, no packets received yet.
[2023.06.16-21.35.17:819][740]LogNet: Warning: UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 20.01, Real: 20.01, Good: 20.01, DriverTime: 20.04, Threshold: 20.00, [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID
[2023.06.16-21.35.17:820][741]LogNet: Error: UEngine::BroadcastNetworkFailure: FailureType = ConnectionTimeout, ErrorString = UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 20.01, Real: 20.01, Good: 20.01, DriverTime: 20.04, Threshold: 20.00, [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID, Driver = PendingNetDriver IpNetDriver_2147482490
[2023.06.16-21.35.17:821][741]LogNet: Warning: Network Failure: PendingNetDriver[ConnectionTimeout]: UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 20.01, Real: 20.01, Good: 20.01, DriverTime: 20.04, Threshold: 20.00, [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID
[2023.06.16-21.35.17:822][741]LogNet: NetworkFailure: ConnectionTimeout, Error: 'UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 20.01, Real: 20.01, Good: 20.01, DriverTime: 20.04, Threshold: 20.00, [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID'
[2023.06.16-21.35.17:822][741]LogNet: UNetConnection::Close: [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID, Channels: 2, Time: 2023.06.16-21.35.17
[2023.06.16-21.35.17:822][741]LogNet: UNetConnection::SendCloseReason:
[2023.06.16-21.35.17:822][741]LogNet: - Result=ConnectionTimeout, ErrorContext="ConnectionTimeout"
[2023.06.16-21.35.17:822][741]LogNet: UChannel::Close: Sending CloseBunch. ChIndex == 0. Name: [UChannel] ChIndex: 0, Closing: 0 [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID
[2023.06.16-21.35.17:824][741]LogNet: Browse: /Game/Maps/MainMenu?closed
[2023.06.16-21.35.17:824][741]LogNet: DestroyNamedNetDriver IpNetDriver_2147482490 [PendingNetDriver]
[2023.06.16-21.35.17:825][741]LogExit: PendingNetDriver IpNetDriver_2147482490 shut down
[2023.06.16-21.35.17:825][741]LogNet: Connection failed; returning to Entry
[2023.06.16-21.35.17:826][741]LogLoad: LoadMap: /Game/Maps/MainMenu?closed
[2023.06.16-21.35.17:826][741]LogWorld: BeginTearingDown for /Game/Maps/MainMenu
[2023.06.16-21.35.17:826][741]LogWorld: UWorld::CleanupWorld for MainMenu, bSessionEnded=true, bCleanupResources=true
[2023.06.16-21.35.17:827][741]LogSlate: InvalidateAllWidgets triggered. All widgets were invalidated
[2023.06.16-21.35.17:847][741]LogNet: UChannel::CleanUp: ChIndex == 0. Closing connection. [UChannel] ChIndex: 0, Closing: 0 [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: None, Driver: PendingNetDriver None, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID
[2023.06.16-21.35.17:848][741]LogAudio: Display: Audio Device unregistered from world 'None'.
[2023.06.16-21.35.17:848][741]LogNet: UNetConnection::PendingConnectionLost. [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: None, Driver: PendingNetDriver None, IsServer: YES, PC: NULL, Owner: NULL, UniqueId: INVALID bPendingDestroy=0
[2023.06.16-21.35.17:849][741]LogUObjectHash: Compacting FUObjectHashTables data took 0.57ms
[2023.06.16-21.35.17:851][741]LogStreaming: Display: FlushAsyncLoading(53): 1 QueuedPackages, 0 AsyncPackages
[2023.06.16-21.35.17:867][741]LogAudio: Display: Audio Device (ID: 1) registered with world 'MainMenu'.
[2023.06.16-21.35.17:868][741]LogWorldSubsystemInput: UEnhancedInputDeveloperSettings::bEnableWorldSubsystem is false, the world subsystem will not be created!
[2023.06.16-21.35.17:868][741]LogChaos: FPhysicsSolverBase::AsyncDt:-1.000000
[2023.06.16-21.35.17:869][741]LogAIModule: Creating AISystem for world MainMenu
[2023.06.16-21.35.17:870][741]LogLoad: Game class is 'SQGameMode_BP_C'
[2023.06.16-21.35.17:871][741]LogWorld: Bringing World /Game/Maps/MainMenu.MainMenu up for play (max tick rate 0) at 2023.06.16-17.35.17
[2023.06.16-21.35.17:871][741]LogWorld: Bringing up level for play took: 0.000592
[2023.06.16-21.35.17:872][741]LogGameMode: FindPlayerStart: PATHS NOT DEFINED or NO PLAYERSTART with positive rating
[2023.06.16-21.35.17:873][741]LogActor: Warning: Player_C /Game/Maps/MainMenu.MainMenu:PersistentLevel.Player_C_2147482439 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily
[2023.06.16-21.35.17:873][741]LogLoad: Took 0.050743 seconds to LoadMap(/Game/Maps/MainMenu)
EDIT… EDIT…
I created a Blueprint project and use the default create/join sessions without any extra setup and I am able to connect to a listen server. So, I know it’s not a network issue or a closed port issue.
I ran Wireshark to track what was going on but all I could find was an “unable to connect” at port 0. For whatever reason, the CPP game is binding to 192.168.50.115:0 nine times out of ten. Every once in a while it will connect to port 7777 (i.e. 192.168.50.115:7777) and work fine. I am not sure why that happens.
I adjusted the ServerTravel call to:
GetWorld()->ServerTravel("/Game/Maps/Space?listen?Port=7777");
But the results are spotty at best. When I open two editor games (right click on uproject) or launch from editor, it tends to connect to port 7777. When I launch two clients and have one be the host, it more often than not goes to port 0. I build and cook the client often so I don’t think that’s the issue.
On the client (hosting) I get the error:
LogNet: Error: LoadMap: failed to Listen(/Game/Maps/Space?Name=Player?listen?Port=7777)
And on the client (joining) I get the error:
LogNet: Error: UEngine::BroadcastNetworkFailure: FailureType = ConnectionTimeout, ErrorString = UNetConnection::Tick: Connection TIMED OUT. Closing connection.. Elapsed: 20.01, Real: 20.01, Good: 20.01, DriverTime: 20.03, Threshold: 20.00, [UNetConnection] RemoteAddr: 192.168.50.115:0, Name: IpConnection_2147482489, Driver: PendingNetDriver IpNetDriver_2147482490, IsServer: NO, PC: NULL, Owner: NULL, UniqueId: INVALID, Driver = PendingNetDriver IpNetDriver_2147482490
I also have a custom UE_LOG that shows the IP it tried to connect to. As you can see, even though I specified the listen port, it tried going to port 0.
Warning: Joined StarQuest Server: 192.168.50.115:0