BP: Try -> Server connection, else

Hey guys,

My question if fairly simple, at least, I think :wink:

I’ve got a Host and Join button.
Currently the situation is as follows:
When the user presses the host button, a Execute Command happens with ‘open StarterMap?Listen’
When the user presses the join button, a Execute Command happens with ‘open [ip address]’

So yeah that works, but now I want some kind of check to see if the server exists. It wouldn’t be nice to let the user connect neverending to a server that doesn’t exist :slight_smile:

So my question is, how do I check if server exists and how do I create a time-out?
Thanks!

Hi Serellyn,

First of all, I would suggest taking a look at the Blueprint multiplayer session nodes introduced in 4.6, which allow you to advertise, find, and join sessions without using C++ code. I gave an introduction to these in this video.

But to answer your question, generally you would try to contact a server, and if you don’t receive a response within a time-out period, you can assume the server doesn’t exist (or is having other issues that make it unusable).

There are a few network-related timeouts built in to the engine, which you can modify in your DefaultEngine.ini file:

[/Script/OnlineSubsystemUtils.IpNetDriver]
ConnectionTimeout=60.0
InitialConnectTimeout=60.0

When trying to connect with “open [ip address]”, if a server doesn’t exist at that address, the connection attempt will fail after the InitialConnectTimeout.

Hey Ryan, thank you this will help me a lot. I’m actually looking at it now but one thing seems to be missing. In your introduction you use the ‘Show Error Dialog’ blueprint, but it does not show up on my end. Has this blueprint node been removed? if so, has it been replaced with the ‘Event Network Error’ and ‘Event Travel Error’?

And one more thing, if I want to connect directly via IP, can I still use the Join Sessions node or should I then use the ‘open [ip address]’?

Thanks again!

‘Show Error Dialog’ in that project is a custom function that I used to consolidate the logic of managing the UI widgets. I didn’t have time to go into detail on every function on the stream, unfortunately.

You can always connect directly to an IP using the open command, but to use the Join Session node you will need to have a search result from the Find Sessions node. If you’re using OnlineSubsystemNull, it essentially does just connect to an IP under the hood though (as opposed to, say, OnlineSubsystemSteam, which would use the Steam service to connect).