File indexing completed on 2024-04-21 04:02:07

0001 /***************************************************************************
0002 *   KBlocks, a falling blocks game by KDE                                *
0003 *   SPDX-FileCopyrightText: 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com>       *
0004 *                                                                         *
0005 *   SPDX-License-Identifier: GPL-2.0-or-later
0006 ***************************************************************************/
0007 #ifndef KBLOCKSNETCLIENT_H
0008 #define KBLOCKSNETCLIENT_H
0009 
0010 #include <QObject>
0011 #include <QUdpSocket>
0012 #include <QString>
0013 
0014 class KBlocksNetClient : public QObject
0015 {
0016     Q_OBJECT
0017 
0018 public:
0019     KBlocksNetClient(const QString &remoteIP, quint16 localPort);
0020     ~KBlocksNetClient() override;
0021 
0022 public:
0023     int sendData(int count, char *data);
0024     int recvData(int count, char *data);
0025 
0026 Q_SIGNALS:
0027     void dataArrived(int size);
0028 
0029 private:
0030     bool parseIPString(const QString &input, QHostAddress *ip, quint16 *port);
0031 
0032 private Q_SLOTS:
0033     void receivedData();
0034 
0035 private:
0036     QUdpSocket *mpClientSocket = nullptr;
0037 
0038     QHostAddress mLocalAddress;
0039     quint16 mLocalPort;
0040 
0041     QHostAddress mRemoteAddress;
0042     quint16 mRemotePort;
0043 };
0044 
0045 #endif
0046