1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

add udpclient udpserver and use QQtMessage

This commit is contained in:
tianduanrui 2017-10-29 18:06:55 +08:00
parent 64992d1e54
commit 7cab48f9c1
23 changed files with 162 additions and 35 deletions

View File

@ -32,7 +32,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTableWidget" name="tableWidget"/> <widget class="QTableWidget" name="tb"/>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -2,7 +2,7 @@
#include "qqtcore.h" #include "qqtcore.h"
#include "qqtnetwork.h" #include "qqtnetwork.h"
QQTNetworkMessage::QQTNetworkMessage(QObject *parent) : QQTMessage(parent) QQTNetworkMessage::QQTNetworkMessage(QObject *parent) : QQtMessage(parent)
{ {
m_Head = _TCPCMD_TAGHEAD; m_Head = _TCPCMD_TAGHEAD;
m_Size = m_Cmd = m_Uid = m_Sum = 0; m_Size = m_Cmd = m_Uid = m_Sum = 0;

View File

@ -6,7 +6,7 @@
#define _TCPCMD_TAGHEAD 0xAA55 #define _TCPCMD_TAGHEAD 0xAA55
#define _TCPCMD_TAGTAIL 0xCC33C33C #define _TCPCMD_TAGTAIL 0xCC33C33C
class QQTNetworkMessage : public QQTMessage class QQTNetworkMessage : public QQtMessage
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -32,7 +32,7 @@ signals:
public slots: public slots:
// QQTMessage interface // QQtMessage interface
public: public:
void parser(const QByteArray &l) override; void parser(const QByteArray &l) override;

View File

@ -2,7 +2,7 @@
#include "qqtcore.h" #include "qqtcore.h"
QQTSerialMessage::QQTSerialMessage(QObject *parent) : QQTSerialMessage::QQTSerialMessage(QObject *parent) :
QQTMessage(parent) QQtMessage(parent)
{ {
m_Head = _SERIAL_HEAD; m_Head = _SERIAL_HEAD;
m_Size = m_Cmd = m_Sum = 0; m_Size = m_Cmd = m_Sum = 0;

View File

@ -7,7 +7,7 @@
#define _SERIAL_HEAD 0xAA55 #define _SERIAL_HEAD 0xAA55
#define _SERIAL_TAIL 0xCC33 #define _SERIAL_TAIL 0xCC33
class QQTSerialMessage : public QQTMessage class QQTSerialMessage : public QQtMessage
{ {
public: public:
explicit QQTSerialMessage(QObject* parent = 0); explicit QQTSerialMessage(QObject* parent = 0);

View File

@ -52,6 +52,7 @@ void QQtBluetoothClient::installProtocol(QQTProtocol* stack)
void QQtBluetoothClient::uninstallProtocol(QQTProtocol* stack) void QQtBluetoothClient::uninstallProtocol(QQTProtocol* stack)
{ {
Q_UNUSED(stack)
if (!m_protocol) if (!m_protocol)
return; return;
@ -176,6 +177,7 @@ void QQtBluetoothClient::socketDisconnect()
void QQtBluetoothClient::updateProgress(qint64 bytes) void QQtBluetoothClient::updateProgress(qint64 bytes)
{ {
Q_UNUSED(bytes)
//pline() << bytes; //pline() << bytes;
} }

View File

@ -2,7 +2,7 @@
#include "qqtnetwork.h" #include "qqtnetwork.h"
#include "qqtbluetoothclient.h" #include "qqtbluetoothclient.h"
QQtBluetoothServer::QQtBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent) : QBluetoothServer(serverType, parent) QQtBluetoothServer::QQtBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject* parent) : QBluetoothServer(serverType, parent)
{ {
connect(this, SIGNAL(newConnection()), connect(this, SIGNAL(newConnection()),
this, SLOT(comingNewConnection())); this, SLOT(comingNewConnection()));
@ -16,7 +16,7 @@ QQtBluetoothServer::~QQtBluetoothServer()
void QQtBluetoothServer::comingNewConnection() void QQtBluetoothServer::comingNewConnection()
{ {
if(!hasPendingConnections()) if (!hasPendingConnections())
return; return;
QBluetoothSocket* comingSocket = nextPendingConnection(); QBluetoothSocket* comingSocket = nextPendingConnection();
@ -26,23 +26,24 @@ void QQtBluetoothServer::comingNewConnection()
clientSocket->setSocketDescriptor(comingSocket->socketDescriptor(), QBluetoothServiceInfo::RfcommProtocol); clientSocket->setSocketDescriptor(comingSocket->socketDescriptor(), QBluetoothServiceInfo::RfcommProtocol);
} }
void QQtBluetoothServer::installProtocol(QQTProtocol *stack) void QQtBluetoothServer::installProtocol(QQTProtocol* stack)
{ {
if(m_protocol) if (m_protocol)
return; return;
m_protocol = stack; m_protocol = stack;
} }
void QQtBluetoothServer::uninstallProtocol(QQTProtocol *stack) void QQtBluetoothServer::uninstallProtocol(QQTProtocol* stack)
{ {
if(!m_protocol) Q_UNUSED(stack)
if (!m_protocol)
return; return;
m_protocol = NULL; m_protocol = NULL;
} }
QQTProtocol *QQtBluetoothServer::installedProtocol() QQTProtocol* QQtBluetoothServer::installedProtocol()
{ {
return m_protocol; return m_protocol;
} }

View File

@ -57,6 +57,8 @@ void QQTClient::installProtocol(QQTProtocol* stack)
void QQTClient::uninstallProtocol(QQTProtocol* stack) void QQTClient::uninstallProtocol(QQTProtocol* stack)
{ {
Q_UNUSED(stack)
if (!m_protocol) if (!m_protocol)
return; return;
@ -190,6 +192,7 @@ void QQTClient::socketDisconnect()
void QQTClient::updateProgress(qint64 bytes) void QQTClient::updateProgress(qint64 bytes)
{ {
Q_UNUSED(bytes)
//pline() << bytes; //pline() << bytes;
} }

View File

@ -7,11 +7,11 @@
/** /**
* @brief * @brief
*/ */
class QQTSHARED_EXPORT QQTMessage : public QObject class QQTSHARED_EXPORT QQtMessage : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTMessage(QObject *parent = 0) : QObject(parent) {} explicit QQtMessage(QObject* parent = 0) : QObject(parent) {}
public: public:
/** /**
@ -19,7 +19,7 @@ public:
* @param m * @param m
* @param l * @param l
*/ */
virtual void parser(const QByteArray &l) = 0; virtual void parser(const QByteArray& l) = 0;
/** /**
* @brief * @brief
* @param l * @param l

View File

@ -0,0 +1,6 @@
#include "qqtnetworkserver.h"
QQtNetworkServer::QQtNetworkServer(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,17 @@
#ifndef QQTNETWORKSERVER_H
#define QQTNETWORKSERVER_H
#include <QObject>
class QQtNetworkServer : public QObject
{
Q_OBJECT
public:
explicit QQtNetworkServer(QObject *parent = nullptr);
signals:
public slots:
};
#endif // QQTNETWORKSERVER_H

View File

@ -13,7 +13,7 @@ class QQTSHARED_EXPORT QQTProtocol : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTProtocol(QObject *parent = 0); explicit QQTProtocol(QObject* parent = 0);
signals: signals:
qint64 write(const QByteArray& l); qint64 write(const QByteArray& l);
@ -30,13 +30,13 @@ public:
* @param * @param
* @return * @return
*/ */
virtual quint16 splitter(const QByteArray &s) { return 0; } virtual quint16 splitter(const QByteArray&) { return 0; }
/** /**
* @brief * @brief
* @param * @param
* @return 0 no dispatched(others) 1 dispatched(own) * @return 0 no dispatched(others) 1 dispatched(own)
*/ */
virtual bool dispatcher(const QByteArray &m) { return 0; } virtual bool dispatcher(const QByteArray&) { return 0; }
}; };
#endif // QQTPROTOCOL_H #endif // QQTPROTOCOL_H

View File

@ -26,6 +26,7 @@ void QQTSerialPort::installProtocol(QQTProtocol* stack)
void QQTSerialPort::uninstallProtocol(QQTProtocol* stack) void QQTSerialPort::uninstallProtocol(QQTProtocol* stack)
{ {
Q_UNUSED(stack)
if (!m_protocol) if (!m_protocol)
return; return;

View File

@ -2,7 +2,7 @@
#include "qqtnetwork.h" #include "qqtnetwork.h"
QQTServer::QQTServer(QObject *parent) : QQTServer::QQTServer(QObject* parent) :
QTcpServer(parent) QTcpServer(parent)
{ {
} }
@ -12,7 +12,7 @@ QQTServer::~QQTServer()
close(); close();
} }
void QQTServer::incomingConnection(int handle) void QQTServer::incomingConnection(qintptr handle)
{ {
QQTClient* clientSocket = new QQTClient(this); QQTClient* clientSocket = new QQTClient(this);
clientSocket->setSocketDescriptor(handle); clientSocket->setSocketDescriptor(handle);
@ -20,23 +20,25 @@ void QQTServer::incomingConnection(int handle)
clientSocket->installProtocol(m_protocol); clientSocket->installProtocol(m_protocol);
} }
void QQTServer::installProtocol(QQTProtocol *stack) void QQTServer::installProtocol(QQTProtocol* stack)
{ {
if(m_protocol) if (m_protocol)
return; return;
m_protocol = stack; m_protocol = stack;
} }
void QQTServer::uninstallProtocol(QQTProtocol *stack) void QQTServer::uninstallProtocol(QQTProtocol* stack)
{ {
if(!m_protocol) Q_UNUSED(stack)
if (!m_protocol)
return; return;
m_protocol = NULL; m_protocol = NULL;
} }
QQTProtocol *QQTServer::installedProtocol() QQTProtocol* QQTServer::installedProtocol()
{ {
return m_protocol; return m_protocol;
} }

View File

@ -10,7 +10,7 @@ class QQTSHARED_EXPORT QQTServer : public QTcpServer
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QQTServer(QObject *parent = 0); explicit QQTServer(QObject* parent = 0);
~QQTServer(); ~QQTServer();
void installProtocol(QQTProtocol* stack); void installProtocol(QQTProtocol* stack);
@ -20,7 +20,7 @@ public:
signals: signals:
// QTcpServer interface // QTcpServer interface
protected: protected:
void incomingConnection(int handle); virtual void incomingConnection(qintptr handle) override;
private: private:
QQTProtocol* m_protocol; QQTProtocol* m_protocol;
}; };

View File

@ -0,0 +1,6 @@
#include "qqtudpclient.h"
QQtUdpClient::QQtUdpClient(QObject* parent) : QUdpSocket(parent)
{
}

View File

@ -0,0 +1,17 @@
#ifndef QQTUDPCLIENT_H
#define QQTUDPCLIENT_H
#include <QUdpSocket>
class QQtUdpClient : public QUdpSocket
{
Q_OBJECT
public:
explicit QQtUdpClient(QObject* parent = nullptr);
signals:
public slots:
};
#endif // QQTUDPCLIENT_H

View File

@ -0,0 +1,6 @@
#include "qqtudpserver.h"
QQtUdpServer::QQtUdpServer(QObject* parent) : QUdpSocket(parent)
{
}

View File

@ -0,0 +1,17 @@
#ifndef QQTUDPSERVER_H
#define QQTUDPSERVER_H
#include <QUdpSocket>
class QQtUdpServer : public QUdpSocket
{
Q_OBJECT
public:
explicit QQtUdpServer(QObject* parent = nullptr);
signals:
public slots:
};
#endif // QQTUDPSERVER_H

View File

@ -0,0 +1,6 @@
#include "qqtwebserver.h"
QQtWebServer::QQtWebServer(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,17 @@
#ifndef QQTWEBSERVER_H
#define QQTWEBSERVER_H
#include <QObject>
class QQtWebServer : public QObject
{
Q_OBJECT
public:
explicit QQtWebServer(QObject *parent = nullptr);
signals:
public slots:
};
#endif // QQTWEBSERVER_H

View File

@ -253,10 +253,20 @@ DEFINES += __QRENCODE__
##################WebSocket Module############################### ##################WebSocket Module###############################
#if you use QtSoap, open this annotation #if you use QtSoap, open this annotation
DEFINES += __QTSOAP__ DEFINES += __QTSOAP__
#One Ftp Http 单工...
#Multi 半双工(客户端并发,服务器序列) QNetworkAccessManager
#if you use QNetworkAccessManagerSupport , open this annotation
#DEFINES += __NETWORKSUPPORT__
contains (DEFINES, __NETWORKSUPPORT__) {
#QSslError not found, you need recompiler Qt4
#TODO: QT += webkit
}
#Multi New Protocol 全双工 QWebSocket
#if you use QWebSocketSupport , open this annotation #if you use QWebSocketSupport , open this annotation
#DEFINES += __WEBSOCKETSUPPORT__ #DEFINES += __WEBSOCKETSUPPORT__
equals(QKIT_PRIVATE, macOS):DEFINES += __WEBSOCKETSUPPORT__ equals(QKIT_PRIVATE, macOS):DEFINES += __WEBSOCKETSUPPORT__
contains (DEFINES, __WEBSOCKETSUPPORT__) { contains (DEFINES, __WEBSOCKETSUPPORT__) {
QT += websockets
#QSslError not found, you need recompiler Qt4 #QSslError not found, you need recompiler Qt4
#TODO: QT += webkit #TODO: QT += webkit
} }

View File

@ -9,12 +9,8 @@
#FDL1.3 GPLv3 LGPLv2.1 PreviewCommercial #FDL1.3 GPLv3 LGPLv2.1 PreviewCommercial
#2017年10月29日09:16:41 #2017年10月29日09:16:41
#------------------------------------------------- #-------------------------------------------------
SOURCES= \ SOURCES +=
$$PWD/network/qqtnetworkclient.cpp \ HEADERS +=
$$PWD/network/qqtwebclient.cpp
HEADERS= \
$$PWD/network/qqtnetworkclient.h \
$$PWD/network/qqtwebclient.h
#root dir #root dir
@ -185,6 +181,13 @@ contains (DEFINES, __PRINTSUPPORT__) {
} }
#network #network
#udpsocket
SOURCES += \
$$PWD/network/qqtudpclient.cpp \
$$PWD/network/qqtudpserver.cpp
HEADERS += \
$$PWD/network/qqtudpclient.h \
$$PWD/network/qqtudpserver.h
#tcpsocket #tcpsocket
SOURCES += \ SOURCES += \
$$PWD/network/qqtclient.cpp \ $$PWD/network/qqtclient.cpp \
@ -362,13 +365,26 @@ contains(DEFINES, __QTSOAP__) {
} }
contains (DEFINES, __WEBSOCKETSUPPORT__) { contains (DEFINES, __NETWORKSUPPORT__) {
SOURCES += \ SOURCES += \
$$PWD/network/qqtnetworkclient.cpp \
$$PWD/network/qqtnetworkserver.cpp \
$$PWD/network/qqtftpprotocol.cpp \ $$PWD/network/qqtftpprotocol.cpp \
$$PWD/network/qqthttpprotocol.cpp \ $$PWD/network/qqthttpprotocol.cpp \
$$PWD/network/qqtwebprotocol.cpp $$PWD/network/qqtwebprotocol.cpp
HEADERS += \ HEADERS += \
$$PWD/network/qqtnetworkclient.h \
$$PWD/network/qqtnetworkserver.h \
$$PWD/network/qqtftpprotocol.h \ $$PWD/network/qqtftpprotocol.h \
$$PWD/network/qqthttpprotocol.h \ $$PWD/network/qqthttpprotocol.h \
$$PWD/network/qqtwebprotocol.h $$PWD/network/qqtwebprotocol.h
} }
contains (DEFINES, __WEBSOCKETSUPPORT__) {
SOURCES += \
$$PWD/network/qqtwebclient.cpp \
$$PWD/network/qqtwebserver.cpp
HEADERS += \
$$PWD/network/qqtwebclient.h \
$$PWD/network/qqtwebserver.h
}