Pinging other servers to check if they are online with C++

I am making a multiplayer game with multiple concurrent levels and am planning on using a system where each level runs on a separate server. I want the individual level servers to be offline until people try to access them. To do that, I want to ping the level’s server and load it if a response is not returned, but I have no idea how I would do that with C++. Any input is appreciated. Thank you!

Easiest is probably to write a separate proxy program that listens to the appropriate ports for UDP or TCP (as desired.)

When it receives an incoming connection, it spins up the appropriate server process if it’s not already running, and forwards incoming/outgoing traffic between the server and the outside world, working in effect as a reverse NAT proxy. (The server can then bind to other ports, that you don’t expose to the outer world.)

That definitely sounds like a much better solution, but since I am brand new to C++ and Unreal Engine and I have never created a proxy program from scratch before, I don’t really know where to start with that either. Your suggestion did give me an idea I am going to try though. I was planning on having a “lobby” server that players would initially join which would have every player’s previous world and location saved and would send them to that place. I am going to try having players return to the lobby server when they want to change worlds and have that server keep track of which worlds are online.

What’s the upside of doing the reverse NAT proxy thing though? That sounds like a lot of work just to avoid exposing a couple more custom ports on a machine…

Besides, the proxy program wouldn’t just work out of the box. One cannot just join an UE4 process then try to swap it for another without UE4 noticing! You should expect a bunch of issues and bugs, or even security-related errors.

So unless I’m missing something, at the end of the day you’d end up with a lot of work on your hands for the proxy server, PLUS the travel code that you’d have to code anyway…

EDIT: You should also know that it takes some time to spool up a new UE4 dedicated server instance. Depending on the frequency of level changes, and the probability of requiring a new instance upon changing levels, it might get annoying for your players. Other issues are gameplay related: Say this game has some PvP component and one player is chasing another, if the lead player gets stuck 30sec because of a server start, then the chasing playing will catch up for reasons that are unrelated to the intended gameplay.

That is a very good point. Are there any ways I could make a server with no players on it use less of the computer’s resources rather than completely shutting it down?

It depends what you mean by computer resources. (I haven’t had time to try anything of this sort yet, so this is just speculation…)
If you’re talking about the RAM usage, I’m not sure there’s much that could be done, and even if you could, returning the server to a useable state would still take a few seconds.
If you’re talking about CPU usage, I’m pretty sure that the best solution would be to code a “no players” state in your gameplay code that disables all sources of CPU usage like AI, navigation, etc… You could also lower the framerate drastically, it would be less effective that going deep into your code to disable things, but the ratio effort vs reward would be very high.

Thanks for your input! I am using dedicated servers so I don’t think I will have to worry about framerate, but I will work on disabling sources of CPU usage.

Sorry, I meant tickrate, not framerate! It’s a solution that should not be so quickly discarded for dedicated servers.

If you’re hosting anything for real on the Internet today, you pretty much must have a reverse proxy implementation of some sort. Having a public-facing IP for each and every game server won’t end well.
Once you have an unreal-forwarder reverse proxy, you can start adding smarts to it, spreading your host processes across many different machines, and such. It also provides a nice place to slide in things such as cross-instance chat.