Jump to content
  • 0

Check if server is online or not


Vhaeriel

Question

Hello

 

I make a launcher for my game, but i had a little problem.

I want to check if my game server is online or not

 

using (UdpClient udpClient = new UdpClient())
            {
                try
                {
                    udpClient.Connect("xxx.xxx.xxx.xxx", 5400);
                    label3.Text = "En Ligne";
                }
                catch (Exception)
                {
                    label3.Text = "Hors Ligne";
                }
            }

The problem is, the server is "all time" online, even if the .exe is not running

Any idea ?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 1

UDP ports don't have any sort of connection handshake like TCP which is why they are harder to check. For your app as soon as your "connect" it's gonna say the connection is good. Only way for it to know otherwise is if it sends data to the server and the server doesn't send something back which means you need to know how to talk to the server. We use a library called Lidgren for that. 

 

Because Lidgren is a C# library that you can't integrate into all projects I host a status checker page. (Same as what the games page uses)

 

The following will return the number of players online, or -1 if it cannot talk to your server. 

 

https://www.ascensiongamedev.com/resources/status.php?host=xxx.xxx.xxx.xxx&port=5400

 

You can load that for your patcher but I do have a 3-5 minute cache on it so it maybe a little delayed. 

Link to comment
Share on other sites

  • 0

Out of curiousity, why are you making a launcher exactly? The client itself has an updater in it nowadays.

 

And I am pretty sure that's because UDP is connectionless, it doesn't care whether you are managing to connect or not and just throws your connection out there. The Connect method is a little bit misleading, as it simply sets a default endpoint on the underlying class to send your data to later.

 

You'd have to send data and get something back to really make sure your system is working.

 

Link to comment
Share on other sites

  • 0
3 hours ago, Joyce said:

Out of curiousity, why are you making a launcher exactly? The client itself has an updater in it nowadays.

 

It's a "multi" launcher for my webapp, bot, game, and display image for news, patchnote, etc...

 

Quote

You'd have to send data and get something back to really make sure your system is working.

 

The problem is, the port 5400 on my server is ALWAYS open, not only when the exe is running, it's why the code will all time display "Online".. :/

 

Link to comment
Share on other sites

  • 0
1 hour ago, Vhaeriel said:

The problem is, the port 5400 on my server is ALWAYS open, not only when the exe is running, it's why the code will all time display "Online".. :/

 

4 hours ago, Joyce said:

You'd have to send data and get something back to really make sure your system is working.


You need to do what the client does (send data) like Joyce said.

In Beta 7 (tentative release is end of June) I plan to rework the netcode so that we can check the server status via unconnected Lidgren messages. No response would be offline.

Link to comment
Share on other sites

×
×
  • Create New...