# Cannot create/connect server with c++ code.

**URL:** <https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 27, 2014, 9:10am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076 "2014-05-27T09:10:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 27, 2014, 9:10am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/1 "2014-05-27T09:10:22Z")

</div>

Well, I don’t know if this is related to my previous [post](https://forums.unrealengine.com/showthread.php?7237-Help-on-FindSessions-always-return-0-result) 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:

```auto

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

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

```

Anyone has any clue what’s wrong with this?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 27, 2014, 9:58am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/2 "2014-05-27T09:58:16Z")

</div>

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 🙂

's the most important function:

```auto

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

```

🙂

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 27, 2014, 10:00am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/3 "2014-05-27T10:00:40Z")

</div>

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:

```auto

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…

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 27, 2014, 10:11am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/4 "2014-05-27T10:11:01Z")

</div>

the critical Game Session function is this:

```auto

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 🙂

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 27, 2014, 10:26am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/5 "2014-05-27T10:26:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 1:52am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/6 "2014-05-29T01:52:21Z")

</div>

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:

```auto

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

```

Could this be the core of the problem?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 29, 2014, 3:06am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/7 "2014-05-29T03:06:21Z")

</div>

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)

```auto

[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

```

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 3:14am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/8 "2014-05-29T03:14:37Z")

</div>

Yes, I have that. _cry_

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

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 29, 2014, 6:00am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/9 "2014-05-29T06:00:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 6:29am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/10 "2014-05-29T06:29:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 6:41am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/11 "2014-05-29T06:41:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 29, 2014, 8:11am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/12 "2014-05-29T08:11:09Z")

</div>

> [@KillerPenguin;61479](#):
>
> 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!

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 8:24am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/13 "2014-05-29T08:24:39Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 8:28am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/14 "2014-05-29T08:28:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ryan\_Gerleve](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ryan\_Gerleve](https://forums.unrealengine.com/u/Ryan_Gerleve)\
**Post date:** [May 29, 2014, 10:17pm UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/15 "2014-05-29T22:17:58Z")

</div>

> [@KillerPenguin;61475](#):
>
> Oh gosh, so shooter demo actually use a real steam API?

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

> [@KillerPenguin;61533](#):
>
> Does serverTravel(‘‘Map?Listen’’) automatically open a new listen server?

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?

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 29, 2014, 11:39pm UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/16 "2014-05-29T23:39:20Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 30, 2014, 3:29am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/17 "2014-05-30T03:29:15Z")

</div>

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…

```auto

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

```

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [May 30, 2014, 10:02am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/18 "2014-05-30T10:02:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KillerPenguin](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/killerpenguin/32/1005607_2.png) [@KillerPenguin](https://forums.unrealengine.com/u/KillerPenguin)\
**Post date:** [June 2, 2014, 5:14am UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/19 "2014-06-02T05:14:22Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![cgrebeld](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cgrebeld](https://forums.unrealengine.com/u/cgrebeld)\
**Post date:** [December 29, 2014, 9:12pm UTC](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076/20 "2014-12-29T21:12:48Z")

</div>

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?

[Next page](https://forums.unrealengine.com/t/cannot-create-connect-server-with-c-code/5076.md?page=2)
