How to choose the port at runtime?

I want to launch two servers (same IP, different ports)

`“C:.…\UnrealEditor.exe” “C:.…\MyProject.uproject” -game -Port=7777

`“C:.…\UnrealEditor.exe” “C:.…\MyProject.uproject” -game -Port=7778

And I want to launch a single client.

Without finishing the client execution:
1-I want to connect to a first server session
2-Leave the session
3-And connect to a session on the second server
(It is only for testing purposes)

So I need to choose the port at runtime on the client (from a UI)

Is there a function in C++ that allows me to do this?

Thank you so much


Note: I know I can do it as follows… but I want to do it without closing the client execution. It is to check that everything has been cleaned correctly.
And the user does not need to restart the execution of the program to connect to another server.


Connection to host:

From console (~): open 127.0.0.1:7777
From blueprints: OpenLevel node with the same params
From c++: bp’s node is fine: UGameplayStatics::OpenLevel()

Leaving the game:
open L_MyLevel, you can use main menu map for example. Note that you can connect from server1 to server2 directly, so whether you need this is up to you.

Hosting the listen server:
open L_MyLevel?listen

Fyi, nice guide about ue’s network basics: Multiplayer Network Compendium | An Unreal Engine Blog by Cedric Neukirchen

Also, your PIE’s server is running on port 17777 by default. may be useful for debug sometimes.

1 Like

The console commands work great.

I’ll try C++ too.

Thank you very much for the information and your help.
Very appreciated!!

this is great too

https://docs.unrealengine.com/udk/Three/ConsoleCommands.html

https://docs.unrealengine.com/udk/Three/CommandLineArguments.html

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.