#ifndef PINGER_H #define PINGER_H #include #include #include class QUdpSocket; /** This class is used to ping any QuakeWorld server @author Mihawk @file Pinger.h @date 27/10/2012 */ class Pinger : public QObject { Q_OBJECT public: /** Constructor. @param host The host we are going to ping @param port The host's port */ Pinger(const QHostAddress& host, quint16 port, QObject *parent = 0); /** Starts the pinging process */ void ping(); signals: /** Called when we received an answer from the server sending the time diff between the call to ping() and now as the ping. @param host The host we are pinging @param port The host's port @param ping The ping we got from this server */ void finished(const QHostAddress& host, quint16 port, int ping); protected: /** Called when the pinging process times out this timeout is set to 1000ms. @param e The timer event */ void timerEvent(QTimerEvent *e); private slots: /** Called when we received an answer from the server sending the time diff between the call to ping() and now as the ping. This function will emit the finished signal. */ void pong(); private: QUdpSocket* mySocket; // Our socket QTime myTime; // Time used for calculating the ping QHostAddress myHost; // Host to be pinged quint16 myPort; // Host's port int myTimerID;// Timer used for timing out an ping request }; #endif // PINGER_H