Cannot create/connect server with c++ code.

Well, I don’t know if this is related to my previous post but somehow I cannot create or join server from c++ code.
I could use ?listen/ip address on the UT4’s shortcut to create/join the server, but I couldn’t do the same with c++ ServerTravel and ClientTravel even with absolute ip.

The actual code i used is:



mWorld->ServerTravel(TEXT("/Game/Maps/MyMap?listen"));

mWorld->ClientTravel("127.0.0.1", TRAVEL_Absolute);


Anyone has any clue what’s wrong with this?

It’s not as simple as just restarting with the ?listen option

You have to setup some things in via the Game Mode and a GameSession

Check out how shooter game does it!

In particular check out the GameSession class :slight_smile:

's the most important function:


bool AVictoryGameSession::HostSession(int32 ControllerId, FName SessionName, const FString & GameType, bool bIsLAN, bool bIsPresence, int32 MaxNumPlayers)
{
  //...

:slight_smile:

Yes, . I have all those gameSession, gameMode, delegates and host functions… I’m trying to follow shooter demo as much as I could.

On a closer debuging, I noticed that when I call ServerTravel inside my project, there’s no logs notifying that my game socket is being queued like when I open it with command line (or shooter demo).

In other word, I’m missing this from my log:



LogInit: WinSock: Socket queue 131072 / 131072
[2014.05.27-09.55.53:198]  0]LogNet: GameNetDriver IpNetDriver_0 IpNetDriver listening on port 7777


So where/how the heck do I invoke this WinSocket. I’m as close as shifting from IOnlineSubsystem to pure WinSocket now…

the critical Game Session function is this:


OnCreatePresenceSessionComplete(GameSessionName, true);

You should log to make sure this is being called!

You say you “have it all” but it is in that lot of code that the critical part needs to happen, so log it up till you see where the chain of events is not occurring :slight_smile:

Yes I have that. It returned with success too… I logged everything on these issue. The only thing I could found was that the socket isn’t being queud

No any other help on this subject? T_T

I digged deep and found that log on “Socket queue” is inside UIpNetDriver::InitBase(). But I couldn’t find where does IOnlineSubsystem invoke such class…

ps. Just found another clue on my log, it said:


LogOnline:Warning: Unable to load default OnlineSubsystem module Steam, using NULL interface

Could this be the core of the problem?

oooooh

I forgot to mention

you need a special config setup and also build cs!

you should copy over the shootergame build cs, the parts related to steam, and also check out the config file!

I use something like this (defaultengine.ini)


[Core.Log]
LogNet=Log
LogOnline=verbose ;online logging
LogAnalytics=log

[/Script/Engine.GameEngine]
!NetDriverDefinitions=ClearArray
;+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemUtils.IpNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")

[OnlineSubsystem]
;DefaultPlatformService=Null
DefaultPlatformService=Steam
PollingIntervalInMs=20

[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=212960
GameServerQueryPort=27015
bRelaunchInSteam=false
GameVersion=1.0.0.0
bVACEnabled=1
bAllowP2PPacketRelay=true
P2PConnectionTimeout=90

[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
AllowDownloads=false

Yes, I have that. cry

I think it’s more about unable to load Steam module… any clue on that?

do you have steam already loaded and running in the background when you try to play your game?

Oh gosh, so shooter demo actually use a real steam API? I thought it was just a mocked up version.

Ok going to set up my steam sdk. now…

Thx!

ps. But wait, when I tested out the Shooter demo, there’s no “steam already loaded and running in the background” though. How does that work?

I am not sure how steam integration works at the moment, it has changed since the Beta, hopefully someone from Epic can take this further!

Well, I changed from Steam to OnlineSubsystemNull just for faster prototype.

I kinda understand now that unlike shooter entry, my game doesn’t start out with any listening port.
I don’t get how they start that process in the shooter demo though… (I.E. How do I make my .exe start with ?listen at the end.)

Ok, I think my ultimate question is, What c++ code do I use to switch my game into a server and client?

Does serverTravel(‘‘Map?Listen’’) automatically open a new listen server?

Yes, if you have access to the Steam SDK ShooterGame should work over Steam.

Yes, it definitely should. Calling ClientTravel directly will bypass the OnlineSubsystem stuff. After you call ServerTravel, on the other instance does the console command “open 127.0.0.1” connect to the server successfully?

Nope, I could not use console command to connect to the any game that was create with c++ serverTravel(map?Listen).

GetNetMode() always say that my game is a standalone too, not a listen server. Starting ut4 with ?Listen] in command line does make everything work nicely though, the game start out as a listen server. But the point is to make my game turn into a listen server only after a host button is pressed…

ps. Oh gosh, I just found out that Shooter’s EntryLevel always start out as a listening server. How do you do that?

For now I have to use this as a work around. Basically if a game front isn’t a listen server then immediately reopen it with ?listen. I hope someone can show me a better light though…


void AFrontGui::BeginPlay()
{
	if (GetNetMode() != NM_ListenServer)
	{
		mWorld->ServerTravel(TEXT("/Game/Maps/GameFront?listen"));
	}
}

This only works in 64Bit debug mode too. The client fail to join sessions which are created from 32B shipping built…

Seriously, when is the network document going to come? I read somewhere that Epic is going to try to keep a close watch on networking questions until its release, but so far I don’t see much help on this topic…

Very frustrated atm…

Hi,
We’ve run into this exact problem. We are following the ShooterGame code but trying to create a joinable session when the Lobby UI comes up - without travelling to a new map using the “?listen” URL.

The missing step seems to be that the **GameNetDriver **is not being created. Normally this happens in UWorld::Listen.

Did you find a cleaner workaround for this puzzle?