How do you create a server & clients? (In code, not in editor)

I am trying to make a game/project into a server, and I want to be able to create clients that play in that game as well. Normally, in the Editor, it’s as simple as toggling a flag and setting the amount of clients you want to get the desired results. Using this method, you can also play around in multiple viewports and it will automatically tell you who is a server, client1, client2, etc in the upper corner of each window. I want to do the exact same thing, but while the game is running.

I have set breakpoints to see where the code runs and found them in debuggercommands.h/.cpp. Stepping through the code shows very simple function/methods that handle the mechanism for flagging a server, setting the num of clients, and creating new viewports. However, the code that executes these commands only works with the Editor and I can’t track down the code that handles that in the Engine. I have tried “Finding all references” with the variables to see if they are at least being used in Engine, but the aren’t.

I have also looked at the ShooterGame example and the Network Tutorials but still can’t find the mechanism that sets a game to be a server, and spawns multiple clients in code. Any ideas?

You can create Server and clients via commandline, when opening new instances of your game

my work flow is as follows

  • run the server commandline

  • new game instance starts loading from commandline

  • run the client commandline

  • new game instance runs and connects to the first one

#Server Commandline

RunServer.bat

"E:\VictoryUE4\UnrealEngine-4.1\Engine\Binaries\Win64\UE4Editor.exe" "C:\Users\Rama\Documents\Unreal Projects\VictoryGame\VictoryGame.uproject" Victory?listen -game -ResX=800 -ResY=900 -WinX=0 -WinY=20 -log

#Client Commandline

RunClient.bat

"E:\VictoryUE4\UnrealEngine-4.1\Engine\Binaries\Win64\UE4Editor.exe" "C:\Users\Rama\Documents\Unreal Projects\VictoryGame\VictoryGame.uproject" 127.0.0.1 -game -ResX=800 -ResY=900 -WinX=800 -WinY=20 -log

#map name

in this part

Victory?listen -game

Victory is the map name instead of Content/Maps/

I tried what you said, but I get a Black Screen on my Client. Any ideas why?