00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>. 00004 ** Contact: https://www.qt.io/licensing/ 00005 ** 00006 ** This file is part of the QtWebSockets module of the Qt Toolkit. 00007 ** 00008 ** $QT_BEGIN_LICENSE:BSD$ 00009 ** Commercial License Usage 00010 ** Licensees holding valid commercial Qt licenses may use this file in 00011 ** accordance with the commercial license agreement provided with the 00012 ** Software or, alternatively, in accordance with the terms contained in 00013 ** a written agreement between you and The Qt Company. For licensing terms 00014 ** and conditions see https://www.qt.io/terms-conditions. For further 00015 ** information use the contact form at https://www.qt.io/contact-us. 00016 ** 00017 ** BSD License Usage 00018 ** Alternatively, you may use this file under the terms of the BSD license 00019 ** as follows: 00020 ** 00021 ** "Redistribution and use in source and binary forms, with or without 00022 ** modification, are permitted provided that the following conditions are 00023 ** met: 00024 ** * Redistributions of source code must retain the above copyright 00025 ** notice, this list of conditions and the following disclaimer. 00026 ** * Redistributions in binary form must reproduce the above copyright 00027 ** notice, this list of conditions and the following disclaimer in 00028 ** the documentation and/or other materials provided with the 00029 ** distribution. 00030 ** * Neither the name of The Qt Company Ltd nor the names of its 00031 ** contributors may be used to endorse or promote products derived 00032 ** from this software without specific prior written permission. 00033 ** 00034 ** 00035 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00036 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00037 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00038 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00039 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00040 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00041 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00042 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00043 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00044 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00045 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 00046 ** 00047 ** $QT_END_LICENSE$ 00048 ** 00049 ****************************************************************************/ 00050 #ifndef ECHOCLIENT_H 00051 #define ECHOCLIENT_H 00052 00053 #include <QtCore/QObject> 00054 #include <QtWebSockets/QWebSocket> 00055 #include <QTimer> 00056 #include <chrono> 00057 00058 class Client : public QObject 00059 { 00060 Q_OBJECT 00061 public: 00062 explicit Client(const QUrl &url, bool debug = false, QObject *parent = Q_NULLPTR); 00063 00064 Q_SIGNALS: 00065 void closed(); 00066 00067 private Q_SLOTS: 00068 void onConnected(); 00069 void sendMsg(const QString &key); 00070 void onTextMessageReceived(QString message); 00071 00072 private: 00073 QWebSocket m_webSocket; 00074 QUrl m_url; 00075 bool m_debug; 00076 double i_; 00077 QTimer timer_; 00078 QTimer timer2_; 00079 }; 00080 00081 #endif // ECHOCLIENT_H