checking server status with given IP

(I am using the UNet system)
I have a database where I store the active servers so when a client runs the game he will receive a list of active servers with the ip address for each server, what I am trying to do is to notify the database when the server goes offline so it will get deleted from the list of the active servers. is there a way to check if a server is running or not so I can know when it goes offline? I am not sure if trying to connect to the server directly will help because there are two reasons for a connection failer: the server is not running or the client is offline, and what I want to only be notified about is when the server is not running ONLY so i can delete it from the active servers list on the database.

A hearbeat would probably be the best. Say server sends a heartbeat every x seconds. If a heartbeat is not sent for y seconds. Remove it

thank you for the reply, I already thought of that but I dont know how and where to do it, like is it sent to the client that tried to access the server list? or do I have to run a game 24/7 on my pc to recieve those heartbeats? and how to send them at all? can you give a link or write something?

Uhm, the Matchmaking server could recieve those heartbeats? So where ever the matches are stored you can integrate this. But if your DB is simply accessed by web requests then you could do the heartbeats though PHP. Every 5 seconds the game server can send a Webrequest wich will update a “LastHeartbeat” column. Then when a client wants the server list, if a LastHearBeat was more than for example 8 seconds ago. Then it will not be included and given to the client and it will be removed from the DB.

1 Like

I dont suggest using the database since it has a maximum number of visits, I think of making an empty scene with a script which stores a servers list by receives the heartbeats from each server and when the client wants to view the servers list he will send a message to that script and then the script will return another message to the client with the list of the active hosts/servers. the empty scene will run 24/7 and will have an IP address stored in the database, when a player runs the game he will recieve that IP from the database and the rest of the connections will be made with the empty scene which will redyce the database visits count. the only problem is that HOW THE HELL CAN I SEND A NETWORK MESSAGE BETWEEN THE PLAYER AND THE EMPTY SCENE!! (of course the empty scene will run as a server 24/7).
if you have any idea how to do that please tell me, thank you for your time since its a big reply :slight_smile:

Uhm. At this point you are moving away from a database to a masterserver. I think there is one that the unity team made. Or write your own. I wrote my own Console Application that just used sockets to keep track of servers and sockets for clients to request a list. But that requires you to host.

I’d do it with a master server for several reasons. Firstly, you should never let clients directly write to your central database, as it won’t take long before someone thinks it is funny to blow your whole database away. Secondly depending on clients to monitor and update the health of servers is the wrong idea. I’d have a master server which updates the status of all servers in the db.

Alternativley do it through web requests to update the DB

I did that and it took just a day before my QA people got cute and started playing with the DB update web calls.