I am coding my own auto patch and and i wanna display server status in win form any one haw simple code how cheek server status like Online Offline?
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(IP, PORT);
if (sock.Connected == true)
//ONLINE
else
//OFFLINE
sock.Close();
My Teacher [Only registered and activated users can see links. Click Here To Register...]Quote:
are you serious? How do you plan to write a patcher if you cant connect to a specific port and say if it responds or not?
Good luck, you will need it.
PHP Code:
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(IP, PORT);
if (sock.Connected == true)
//ONLINE
else
//OFFLINE
sock.Close();
[Only registered and activated users can see links. Click Here To Register...]Quote:
My Teacher [Only registered and activated users can see links. Click Here To Register...]
static string IP = "79.143.177.32";
static int Port = 9959;
static void Main(string[] args)
{
Console.WriteLine("Server on port {0} is {1}",Port, Online() ? "online" : "offline");
}
static bool Online()
{
TcpClient client = new TcpClient();
try { new TcpClient().Connect(IP,Port); return true; }
catch { return false; }
}
Should probably disconnect the socket before returning.Quote:
To check if it's on (or actually, if it's in the state to accept connections), you basically try to connect to it and read from it's result. You could use the Socket class (as provided above) or a TcpClient.
Code:static string IP = "79.143.177.32"; static int Port = 9959; static void Main(string[] args) { Console.WriteLine("Server on port {0} is {1}",Port, Online() ? "online" : "offline"); } static bool Online() { TcpClient client = new TcpClient(); try { new TcpClient().Connect(IP,Port); return true; } catch { return false; } }