PDA

View Full Version : How to ping a server ?



Nyphel
23rd April 2007, 10:03
Hi,

I've a simple application that alerts the user when he got new mails on our Intranet messagery server.

To know if there are new mails, I use a QTcpSocket connected to our Intranet messagery server on port 143, and I request for new mails with IMAP protocol. When I can't get the answer, I show an error message saying that the connection as failed, and that the user should check is connection to the network.

The matter is that the user could be well connected but our messagery server would be down.
So, before showing the error, I should test :
- if I can ping our messagery server
- if I can ping another Intranet server

Pinging the messagery server is simple, with IMAP : I've just to tell him that I want a connection.
But I don't know how to ping another Intranet server, nor on wich port. I would like to do a classical 'ping servername'.

Is it possible, without calling external libraries ?

Thanks for your help ! :)

wysota
23rd April 2007, 10:09
"ping" uses the ICMP protocol and not TCP and there are no "ports" in ICMP. The simplest way would be to call the system tool ping, because creating ICMP packets requires superuser priviledges, so there is a good chance you won't be able to forge it in a user application. Also beware of the fact that the modern policy (mainly in Windows) says that pings should be blocked, so you might not get any result back. I would suggest trying to connect to a different service (like http) instead.

Nyphel
23rd April 2007, 11:27
Thanks for the tip :).

Here is my situation :
- server A : provides acces to external services (Web), through a proxy
- server B : provides some internal services, like FTP, HTTP, ...
- server C : provides some internal servicies, like IMAP messagery, DNS, ...

So, what I will test is :
- if the IMAP service is running on server C, with an IMAP request
- if the DNS service is running on server C, with a QHttp request targetting an intranet web site (HTTP service provided by server B, but DNS resolved on server C)
- if the B server is running, testing an intranet HTTP request with the server IP (in order not to use the DNS service on server C)
- if the server A is running, testing an external QHTTP request

That's a good idea !
I was on my "ping" solution snce this morning, for nothing :)