62 lines
1.2 KiB
C
62 lines
1.2 KiB
C
|
|
#ifndef MYTCPSERVER_H
|
|||
|
|
#define MYTCPSERVER_H
|
|||
|
|
|
|||
|
|
#include <QDialog>
|
|||
|
|
#include <QTcpServer>
|
|||
|
|
#include <QFile>
|
|||
|
|
|
|||
|
|
#pragma pack(1)
|
|||
|
|
|
|||
|
|
//数据包头
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
short int cmd; //命令
|
|||
|
|
char check;//异或校验
|
|||
|
|
unsigned int dataSize;//长度
|
|||
|
|
} FilePkgHead;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief The MyTcpServer class 文件传输服务器 单连接
|
|||
|
|
*/
|
|||
|
|
class MyTcpServer: public QTcpServer
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
public:
|
|||
|
|
MyTcpServer(QObject *parent = NULL);
|
|||
|
|
~MyTcpServer();
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
//新的连接
|
|||
|
|
#ifdef Q_OS_WIN
|
|||
|
|
void incomingConnection(qintptr socketDescriptor);
|
|||
|
|
#endif
|
|||
|
|
#ifdef Q_OS_LINUX
|
|||
|
|
void incomingConnection(int handle);
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
public slots:
|
|||
|
|
void connectionHandle();//协议处理
|
|||
|
|
void disconnectHandle(); //断开连接
|
|||
|
|
//数据打包
|
|||
|
|
QByteArray createDataPacket(int cmd1, int cmd2, QByteArray data);
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
qint64 totalBytes; //数据总大小
|
|||
|
|
QByteArray m_fileBuffer_Send; //缓冲文件,用于发送
|
|||
|
|
QByteArray m_fileBuffer_Recv; //缓冲文件,用于接收
|
|||
|
|
QTcpSocket *m_socket; //客户端
|
|||
|
|
QString fileName;
|
|||
|
|
|
|||
|
|
QString m_firstFilePath;//根目录前缀
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
void reflashFileTrans();
|
|||
|
|
|
|||
|
|
signals:
|
|||
|
|
void recvFileSuccess(QString filePath);
|
|||
|
|
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#endif // MYTCPSERVER_H
|