From 7cab48f9c127f38eed6c57af6cf259d52e1376b7 Mon Sep 17 00:00:00 2001
From: tianduanrui <2407223896@qq.com>
Date: Sun, 29 Oct 2017 18:06:55 +0800
Subject: [PATCH] add udpclient udpserver and use QQtMessage
---
examples/VegeTablesPrice/mainwindow.ui | 2 +-
.../qqtnetworkexample/qqtnetworkmessage.cpp | 2 +-
.../qqtnetworkexample/qqtnetworkmessage.h | 4 +--
.../qqtnetworkexample/qqtserialmessage.cpp | 2 +-
examples/qqtnetworkexample/qqtserialmessage.h | 2 +-
src/network/qqtbluetoothclient.cpp | 2 ++
src/network/qqtbluetoothserver.cpp | 15 +++++-----
src/network/qqtclient.cpp | 3 ++
src/network/qqtmessage.h | 6 ++--
src/network/qqtnetworkserver.cpp | 6 ++++
src/network/qqtnetworkserver.h | 17 +++++++++++
src/network/qqtprotocol.h | 6 ++--
src/network/qqtserialport.cpp | 1 +
src/network/qqtserver.cpp | 16 +++++-----
src/network/qqtserver.h | 4 +--
src/network/qqtudpclient.cpp | 6 ++++
src/network/qqtudpclient.h | 17 +++++++++++
src/network/qqtudpserver.cpp | 6 ++++
src/network/qqtudpserver.h | 17 +++++++++++
src/network/qqtwebserver.cpp | 6 ++++
src/network/qqtwebserver.h | 17 +++++++++++
src/qqt_header.pri | 10 +++++++
src/qqt_source.pri | 30 ++++++++++++++-----
23 files changed, 162 insertions(+), 35 deletions(-)
create mode 100644 src/network/qqtnetworkserver.cpp
create mode 100644 src/network/qqtnetworkserver.h
create mode 100644 src/network/qqtudpclient.cpp
create mode 100644 src/network/qqtudpclient.h
create mode 100644 src/network/qqtudpserver.cpp
create mode 100644 src/network/qqtudpserver.h
create mode 100644 src/network/qqtwebserver.cpp
create mode 100644 src/network/qqtwebserver.h
diff --git a/examples/VegeTablesPrice/mainwindow.ui b/examples/VegeTablesPrice/mainwindow.ui
index 3832726b..31e6c14d 100644
--- a/examples/VegeTablesPrice/mainwindow.ui
+++ b/examples/VegeTablesPrice/mainwindow.ui
@@ -32,7 +32,7 @@
-
-
+
diff --git a/examples/qqtnetworkexample/qqtnetworkmessage.cpp b/examples/qqtnetworkexample/qqtnetworkmessage.cpp
index 47a6b16a..c8b0e53b 100644
--- a/examples/qqtnetworkexample/qqtnetworkmessage.cpp
+++ b/examples/qqtnetworkexample/qqtnetworkmessage.cpp
@@ -2,7 +2,7 @@
#include "qqtcore.h"
#include "qqtnetwork.h"
-QQTNetworkMessage::QQTNetworkMessage(QObject *parent) : QQTMessage(parent)
+QQTNetworkMessage::QQTNetworkMessage(QObject *parent) : QQtMessage(parent)
{
m_Head = _TCPCMD_TAGHEAD;
m_Size = m_Cmd = m_Uid = m_Sum = 0;
diff --git a/examples/qqtnetworkexample/qqtnetworkmessage.h b/examples/qqtnetworkexample/qqtnetworkmessage.h
index b8d7c760..9c17a2dd 100644
--- a/examples/qqtnetworkexample/qqtnetworkmessage.h
+++ b/examples/qqtnetworkexample/qqtnetworkmessage.h
@@ -6,7 +6,7 @@
#define _TCPCMD_TAGHEAD 0xAA55
#define _TCPCMD_TAGTAIL 0xCC33C33C
-class QQTNetworkMessage : public QQTMessage
+class QQTNetworkMessage : public QQtMessage
{
Q_OBJECT
public:
@@ -32,7 +32,7 @@ signals:
public slots:
- // QQTMessage interface
+ // QQtMessage interface
public:
void parser(const QByteArray &l) override;
diff --git a/examples/qqtnetworkexample/qqtserialmessage.cpp b/examples/qqtnetworkexample/qqtserialmessage.cpp
index 3236c096..b17291e1 100644
--- a/examples/qqtnetworkexample/qqtserialmessage.cpp
+++ b/examples/qqtnetworkexample/qqtserialmessage.cpp
@@ -2,7 +2,7 @@
#include "qqtcore.h"
QQTSerialMessage::QQTSerialMessage(QObject *parent) :
- QQTMessage(parent)
+ QQtMessage(parent)
{
m_Head = _SERIAL_HEAD;
m_Size = m_Cmd = m_Sum = 0;
diff --git a/examples/qqtnetworkexample/qqtserialmessage.h b/examples/qqtnetworkexample/qqtserialmessage.h
index 01a1df96..c2f6192d 100644
--- a/examples/qqtnetworkexample/qqtserialmessage.h
+++ b/examples/qqtnetworkexample/qqtserialmessage.h
@@ -7,7 +7,7 @@
#define _SERIAL_HEAD 0xAA55
#define _SERIAL_TAIL 0xCC33
-class QQTSerialMessage : public QQTMessage
+class QQTSerialMessage : public QQtMessage
{
public:
explicit QQTSerialMessage(QObject* parent = 0);
diff --git a/src/network/qqtbluetoothclient.cpp b/src/network/qqtbluetoothclient.cpp
index bfead321..3de5e238 100644
--- a/src/network/qqtbluetoothclient.cpp
+++ b/src/network/qqtbluetoothclient.cpp
@@ -52,6 +52,7 @@ void QQtBluetoothClient::installProtocol(QQTProtocol* stack)
void QQtBluetoothClient::uninstallProtocol(QQTProtocol* stack)
{
+ Q_UNUSED(stack)
if (!m_protocol)
return;
@@ -176,6 +177,7 @@ void QQtBluetoothClient::socketDisconnect()
void QQtBluetoothClient::updateProgress(qint64 bytes)
{
+ Q_UNUSED(bytes)
//pline() << bytes;
}
diff --git a/src/network/qqtbluetoothserver.cpp b/src/network/qqtbluetoothserver.cpp
index 8437ba91..fe88fb30 100644
--- a/src/network/qqtbluetoothserver.cpp
+++ b/src/network/qqtbluetoothserver.cpp
@@ -2,7 +2,7 @@
#include "qqtnetwork.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()),
this, SLOT(comingNewConnection()));
@@ -16,7 +16,7 @@ QQtBluetoothServer::~QQtBluetoothServer()
void QQtBluetoothServer::comingNewConnection()
{
- if(!hasPendingConnections())
+ if (!hasPendingConnections())
return;
QBluetoothSocket* comingSocket = nextPendingConnection();
@@ -26,23 +26,24 @@ void QQtBluetoothServer::comingNewConnection()
clientSocket->setSocketDescriptor(comingSocket->socketDescriptor(), QBluetoothServiceInfo::RfcommProtocol);
}
-void QQtBluetoothServer::installProtocol(QQTProtocol *stack)
+void QQtBluetoothServer::installProtocol(QQTProtocol* stack)
{
- if(m_protocol)
+ if (m_protocol)
return;
m_protocol = stack;
}
-void QQtBluetoothServer::uninstallProtocol(QQTProtocol *stack)
+void QQtBluetoothServer::uninstallProtocol(QQTProtocol* stack)
{
- if(!m_protocol)
+ Q_UNUSED(stack)
+ if (!m_protocol)
return;
m_protocol = NULL;
}
-QQTProtocol *QQtBluetoothServer::installedProtocol()
+QQTProtocol* QQtBluetoothServer::installedProtocol()
{
return m_protocol;
}
diff --git a/src/network/qqtclient.cpp b/src/network/qqtclient.cpp
index cc081ca3..18c52401 100644
--- a/src/network/qqtclient.cpp
+++ b/src/network/qqtclient.cpp
@@ -57,6 +57,8 @@ void QQTClient::installProtocol(QQTProtocol* stack)
void QQTClient::uninstallProtocol(QQTProtocol* stack)
{
+ Q_UNUSED(stack)
+
if (!m_protocol)
return;
@@ -190,6 +192,7 @@ void QQTClient::socketDisconnect()
void QQTClient::updateProgress(qint64 bytes)
{
+ Q_UNUSED(bytes)
//pline() << bytes;
}
diff --git a/src/network/qqtmessage.h b/src/network/qqtmessage.h
index 8ac27e2f..e209e51c 100644
--- a/src/network/qqtmessage.h
+++ b/src/network/qqtmessage.h
@@ -7,11 +7,11 @@
/**
* @brief 语法类 定义报文格式
*/
-class QQTSHARED_EXPORT QQTMessage : public QObject
+class QQTSHARED_EXPORT QQtMessage : public QObject
{
Q_OBJECT
public:
- explicit QQTMessage(QObject *parent = 0) : QObject(parent) {}
+ explicit QQtMessage(QObject* parent = 0) : QObject(parent) {}
public:
/**
@@ -19,7 +19,7 @@ public:
* @param m
* @param l
*/
- virtual void parser(const QByteArray &l) = 0;
+ virtual void parser(const QByteArray& l) = 0;
/**
* @brief 将报文组装为流
* @param l
diff --git a/src/network/qqtnetworkserver.cpp b/src/network/qqtnetworkserver.cpp
new file mode 100644
index 00000000..9a81e54b
--- /dev/null
+++ b/src/network/qqtnetworkserver.cpp
@@ -0,0 +1,6 @@
+#include "qqtnetworkserver.h"
+
+QQtNetworkServer::QQtNetworkServer(QObject *parent) : QObject(parent)
+{
+
+}
diff --git a/src/network/qqtnetworkserver.h b/src/network/qqtnetworkserver.h
new file mode 100644
index 00000000..db71d9ef
--- /dev/null
+++ b/src/network/qqtnetworkserver.h
@@ -0,0 +1,17 @@
+#ifndef QQTNETWORKSERVER_H
+#define QQTNETWORKSERVER_H
+
+#include
+
+class QQtNetworkServer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QQtNetworkServer(QObject *parent = nullptr);
+
+signals:
+
+public slots:
+};
+
+#endif // QQTNETWORKSERVER_H
\ No newline at end of file
diff --git a/src/network/qqtprotocol.h b/src/network/qqtprotocol.h
index 19de0934..8425cff3 100644
--- a/src/network/qqtprotocol.h
+++ b/src/network/qqtprotocol.h
@@ -13,7 +13,7 @@ class QQTSHARED_EXPORT QQTProtocol : public QObject
{
Q_OBJECT
public:
- explicit QQTProtocol(QObject *parent = 0);
+ explicit QQTProtocol(QObject* parent = 0);
signals:
qint64 write(const QByteArray& l);
@@ -30,13 +30,13 @@ public:
* @param 接收到的数据段
* @return 按照协议解析到的数据长度 可用,继续接收,丢弃,粘包。
*/
- virtual quint16 splitter(const QByteArray &s) { return 0; }
+ virtual quint16 splitter(const QByteArray&) { return 0; }
/**
* @brief 语义解析器
* @param 数据包
* @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
diff --git a/src/network/qqtserialport.cpp b/src/network/qqtserialport.cpp
index 5beaac0a..5763dd9d 100644
--- a/src/network/qqtserialport.cpp
+++ b/src/network/qqtserialport.cpp
@@ -26,6 +26,7 @@ void QQTSerialPort::installProtocol(QQTProtocol* stack)
void QQTSerialPort::uninstallProtocol(QQTProtocol* stack)
{
+ Q_UNUSED(stack)
if (!m_protocol)
return;
diff --git a/src/network/qqtserver.cpp b/src/network/qqtserver.cpp
index 3e212a94..e451c376 100644
--- a/src/network/qqtserver.cpp
+++ b/src/network/qqtserver.cpp
@@ -2,7 +2,7 @@
#include "qqtnetwork.h"
-QQTServer::QQTServer(QObject *parent) :
+QQTServer::QQTServer(QObject* parent) :
QTcpServer(parent)
{
}
@@ -12,7 +12,7 @@ QQTServer::~QQTServer()
close();
}
-void QQTServer::incomingConnection(int handle)
+void QQTServer::incomingConnection(qintptr handle)
{
QQTClient* clientSocket = new QQTClient(this);
clientSocket->setSocketDescriptor(handle);
@@ -20,23 +20,25 @@ void QQTServer::incomingConnection(int handle)
clientSocket->installProtocol(m_protocol);
}
-void QQTServer::installProtocol(QQTProtocol *stack)
+void QQTServer::installProtocol(QQTProtocol* stack)
{
- if(m_protocol)
+ if (m_protocol)
return;
m_protocol = stack;
}
-void QQTServer::uninstallProtocol(QQTProtocol *stack)
+void QQTServer::uninstallProtocol(QQTProtocol* stack)
{
- if(!m_protocol)
+ Q_UNUSED(stack)
+
+ if (!m_protocol)
return;
m_protocol = NULL;
}
-QQTProtocol *QQTServer::installedProtocol()
+QQTProtocol* QQTServer::installedProtocol()
{
return m_protocol;
}
diff --git a/src/network/qqtserver.h b/src/network/qqtserver.h
index eb90e0c3..8bc490c7 100644
--- a/src/network/qqtserver.h
+++ b/src/network/qqtserver.h
@@ -10,7 +10,7 @@ class QQTSHARED_EXPORT QQTServer : public QTcpServer
{
Q_OBJECT
public:
- explicit QQTServer(QObject *parent = 0);
+ explicit QQTServer(QObject* parent = 0);
~QQTServer();
void installProtocol(QQTProtocol* stack);
@@ -20,7 +20,7 @@ public:
signals:
// QTcpServer interface
protected:
- void incomingConnection(int handle);
+ virtual void incomingConnection(qintptr handle) override;
private:
QQTProtocol* m_protocol;
};
diff --git a/src/network/qqtudpclient.cpp b/src/network/qqtudpclient.cpp
new file mode 100644
index 00000000..d1060f44
--- /dev/null
+++ b/src/network/qqtudpclient.cpp
@@ -0,0 +1,6 @@
+#include "qqtudpclient.h"
+
+QQtUdpClient::QQtUdpClient(QObject* parent) : QUdpSocket(parent)
+{
+
+}
diff --git a/src/network/qqtudpclient.h b/src/network/qqtudpclient.h
new file mode 100644
index 00000000..8c1c0d97
--- /dev/null
+++ b/src/network/qqtudpclient.h
@@ -0,0 +1,17 @@
+#ifndef QQTUDPCLIENT_H
+#define QQTUDPCLIENT_H
+
+#include
+
+class QQtUdpClient : public QUdpSocket
+{
+ Q_OBJECT
+public:
+ explicit QQtUdpClient(QObject* parent = nullptr);
+
+signals:
+
+public slots:
+};
+
+#endif // QQTUDPCLIENT_H
diff --git a/src/network/qqtudpserver.cpp b/src/network/qqtudpserver.cpp
new file mode 100644
index 00000000..ec872d63
--- /dev/null
+++ b/src/network/qqtudpserver.cpp
@@ -0,0 +1,6 @@
+#include "qqtudpserver.h"
+
+QQtUdpServer::QQtUdpServer(QObject* parent) : QUdpSocket(parent)
+{
+
+}
diff --git a/src/network/qqtudpserver.h b/src/network/qqtudpserver.h
new file mode 100644
index 00000000..f99aea4a
--- /dev/null
+++ b/src/network/qqtudpserver.h
@@ -0,0 +1,17 @@
+#ifndef QQTUDPSERVER_H
+#define QQTUDPSERVER_H
+
+#include
+
+class QQtUdpServer : public QUdpSocket
+{
+ Q_OBJECT
+public:
+ explicit QQtUdpServer(QObject* parent = nullptr);
+
+signals:
+
+public slots:
+};
+
+#endif // QQTUDPSERVER_H
diff --git a/src/network/qqtwebserver.cpp b/src/network/qqtwebserver.cpp
new file mode 100644
index 00000000..6e048c29
--- /dev/null
+++ b/src/network/qqtwebserver.cpp
@@ -0,0 +1,6 @@
+#include "qqtwebserver.h"
+
+QQtWebServer::QQtWebServer(QObject *parent) : QObject(parent)
+{
+
+}
diff --git a/src/network/qqtwebserver.h b/src/network/qqtwebserver.h
new file mode 100644
index 00000000..e6a0f441
--- /dev/null
+++ b/src/network/qqtwebserver.h
@@ -0,0 +1,17 @@
+#ifndef QQTWEBSERVER_H
+#define QQTWEBSERVER_H
+
+#include
+
+class QQtWebServer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QQtWebServer(QObject *parent = nullptr);
+
+signals:
+
+public slots:
+};
+
+#endif // QQTWEBSERVER_H
\ No newline at end of file
diff --git a/src/qqt_header.pri b/src/qqt_header.pri
index 204e510c..8d20020c 100644
--- a/src/qqt_header.pri
+++ b/src/qqt_header.pri
@@ -253,10 +253,20 @@ DEFINES += __QRENCODE__
##################WebSocket Module###############################
#if you use QtSoap, open this annotation
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
#DEFINES += __WEBSOCKETSUPPORT__
equals(QKIT_PRIVATE, macOS):DEFINES += __WEBSOCKETSUPPORT__
contains (DEFINES, __WEBSOCKETSUPPORT__) {
+ QT += websockets
#QSslError not found, you need recompiler Qt4
#TODO: QT += webkit
}
diff --git a/src/qqt_source.pri b/src/qqt_source.pri
index dfc31502..89c4884c 100644
--- a/src/qqt_source.pri
+++ b/src/qqt_source.pri
@@ -9,12 +9,8 @@
#FDL1.3 GPLv3 LGPLv2.1 PreviewCommercial
#2017年10月29日09:16:41
#-------------------------------------------------
-SOURCES= \
- $$PWD/network/qqtnetworkclient.cpp \
- $$PWD/network/qqtwebclient.cpp
-HEADERS= \
- $$PWD/network/qqtnetworkclient.h \
- $$PWD/network/qqtwebclient.h
+SOURCES +=
+HEADERS +=
#root dir
@@ -185,6 +181,13 @@ contains (DEFINES, __PRINTSUPPORT__) {
}
#network
+#udpsocket
+SOURCES += \
+ $$PWD/network/qqtudpclient.cpp \
+ $$PWD/network/qqtudpserver.cpp
+HEADERS += \
+ $$PWD/network/qqtudpclient.h \
+ $$PWD/network/qqtudpserver.h
#tcpsocket
SOURCES += \
$$PWD/network/qqtclient.cpp \
@@ -362,13 +365,26 @@ contains(DEFINES, __QTSOAP__) {
}
-contains (DEFINES, __WEBSOCKETSUPPORT__) {
+contains (DEFINES, __NETWORKSUPPORT__) {
SOURCES += \
+ $$PWD/network/qqtnetworkclient.cpp \
+ $$PWD/network/qqtnetworkserver.cpp \
$$PWD/network/qqtftpprotocol.cpp \
$$PWD/network/qqthttpprotocol.cpp \
$$PWD/network/qqtwebprotocol.cpp
HEADERS += \
+ $$PWD/network/qqtnetworkclient.h \
+ $$PWD/network/qqtnetworkserver.h \
$$PWD/network/qqtftpprotocol.h \
$$PWD/network/qqthttpprotocol.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
+}