46 lines
899 B
C++
46 lines
899 B
C++
#ifndef NETWORK_CONTROLLER_H
|
|
#define NETWORK_CONTROLLER_H
|
|
|
|
#include <QObject>
|
|
#include <QByteArray>
|
|
#include <QUdpSocket>
|
|
#include <QTcpSocket>
|
|
#include <QThread>
|
|
|
|
|
|
class NetworkController : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
typedef enum{
|
|
TYPE_UDP_SERVER = 0,
|
|
TYPE_TCP_SERVER = 1,
|
|
TYPE_UDP_CLIENT = 2,
|
|
TYPE_TCP_CLIENT = 3,
|
|
}NetWorkType;
|
|
|
|
NetworkController(NetWorkType type,QString ip,uint16_t port);
|
|
int SendData(int8_t *data,uint32_t len);
|
|
int ReadData(int8_t *data);
|
|
|
|
~NetworkController();
|
|
|
|
public slots:
|
|
void on_ready_read();
|
|
void on_disconect();
|
|
|
|
signals:
|
|
void on_data_recv();
|
|
void on_conection_ok();
|
|
void on_conection_close();
|
|
void on_send_data(QByteArray);
|
|
private:
|
|
NetWorkType type;
|
|
QUdpSocket *mUDP;
|
|
QTcpSocket *mTcp;
|
|
QIODevice *mCnn;
|
|
QThread mThread;
|
|
};
|
|
|
|
#endif // NETWORK_CONTROLLER_H
|