1 /***************************************************************************
2 *   KBlocks, a falling blocks game by KDE                                *
3 *   Copyright (C) 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com>       *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 ***************************************************************************/
10 #ifndef KBLOCKSNETCLIENT_H
11 #define KBLOCKSNETCLIENT_H
12 
13 #include <QObject>
14 #include <QUdpSocket>
15 #include <QString>
16 
17 class KBlocksNetClient : public QObject
18 {
19     Q_OBJECT
20 
21 public:
22     KBlocksNetClient(const QString &remoteIP, quint16 localPort);
23     ~KBlocksNetClient() override;
24 
25 public:
26     int sendData(int count, char *data);
27     int recvData(int count, char *data);
28 
29 Q_SIGNALS:
30     void dataArrived(int size);
31 
32 private:
33     bool parseIPString(const QString &input, QHostAddress *ip, quint16 *port);
34 
35 private Q_SLOTS:
36     void receivedData();
37 
38 private:
39     QUdpSocket *mpClientSocket = nullptr;
40 
41     QHostAddress mLocalAddress;
42     quint16 mLocalPort;
43 
44     QHostAddress mRemoteAddress;
45     quint16 mRemotePort;
46 };
47 
48 #endif
49 
50