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:
parent
64992d1e54
commit
7cab48f9c1
@ -32,7 +32,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget"/>
|
||||
<widget class="QTableWidget" name="tb"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
6
src/network/qqtnetworkserver.cpp
Normal file
6
src/network/qqtnetworkserver.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "qqtnetworkserver.h"
|
||||
|
||||
QQtNetworkServer::QQtNetworkServer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
17
src/network/qqtnetworkserver.h
Normal file
17
src/network/qqtnetworkserver.h
Normal 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
|
@ -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
|
||||
|
@ -26,6 +26,7 @@ void QQTSerialPort::installProtocol(QQTProtocol* stack)
|
||||
|
||||
void QQTSerialPort::uninstallProtocol(QQTProtocol* stack)
|
||||
{
|
||||
Q_UNUSED(stack)
|
||||
if (!m_protocol)
|
||||
return;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
6
src/network/qqtudpclient.cpp
Normal file
6
src/network/qqtudpclient.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "qqtudpclient.h"
|
||||
|
||||
QQtUdpClient::QQtUdpClient(QObject* parent) : QUdpSocket(parent)
|
||||
{
|
||||
|
||||
}
|
17
src/network/qqtudpclient.h
Normal file
17
src/network/qqtudpclient.h
Normal 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
|
6
src/network/qqtudpserver.cpp
Normal file
6
src/network/qqtudpserver.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "qqtudpserver.h"
|
||||
|
||||
QQtUdpServer::QQtUdpServer(QObject* parent) : QUdpSocket(parent)
|
||||
{
|
||||
|
||||
}
|
17
src/network/qqtudpserver.h
Normal file
17
src/network/qqtudpserver.h
Normal 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
|
6
src/network/qqtwebserver.cpp
Normal file
6
src/network/qqtwebserver.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include "qqtwebserver.h"
|
||||
|
||||
QQtWebServer::QQtWebServer(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
17
src/network/qqtwebserver.h
Normal file
17
src/network/qqtwebserver.h
Normal 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
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user