The behavior you experience is due to the Editor already made a connection and when the server opens a level the already connected client tries to follow.
When you select the Net Mode Play Standalone no connection is made for you
When you select the Net Mode Play as Listen Server the first instance will launch as a listen server and additional players will auto-connect to this listen server.
When you select the Net Mode Play as Client a dedicated server instance will launch and every player will auto-connect to the dedicated server.
If you want to test the joining server flow in Play In Editor (PIE) mode you should select “Play Standalone” to avoid the auto-connect feature of the other Net Modes.
Let’s assume you test with 2 standalone players.
Before either of the players have created or joined a server it is safe to assume that you are standalone (Not connected to anything) so you don’t need to do any authority checks here.
If you want to be sure anyway you can use the “Is Standalone” node which should return true on both players.
Now by using a widget and a button you can let the players either do the OpenLevel with levelname and “listen” option or the IP for joining.
Now use the “Output log” to debug if things go right or wrong.
When the first standalone player attempts to create a listen server you should see something like this in the log.
listening on port 7777
When the second standalone player attempts to join the server the server should see this in the log.
Join succeeded
Now that you established connection between both players “Is Standalone” should return false on both players.
Now you can begin to use “Has Authority” on replicated Actors spawned by the Server to branch listen-server and client logic.
But, what happens if both players try to OpenLevel with levelname and “listen” option?
My problem is that I don’t know if there is already a server listening to a connection. This is why I though to use a session, and the first thing to do before try to create one is look a session. If there isn’t any try to create it.