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

remove findservermanager

This commit is contained in:
tianduanrui 2020-03-15 21:01:39 +08:00
parent 80b29103db
commit b4f21807bd
2 changed files with 0 additions and 300 deletions

View File

@ -1,105 +0,0 @@
#include <qqtfindservermanager.h>
#include <qqtframe.h>
QQtBeServerManager::QQtBeServerManager ( QObject* parent ) : QObject ( parent )
{
s0 = new QQtUdpServer ( this );
s0->bind ( 4408, QQtUdpServer::ShareAddress );
p3line() << s0->peerAddress() << s0->peerPort();
m0 = new QQtBeServerProtocolManager ( this );
//m0->setLocalIpPort ( s0->localAddress().toString(), 4409 );
m0->setLocalIpPort ( QHostAddress ( QHostAddress::AnyIPv4 ).toString(), 4409 );
m0->registerProtocol<QQtBeServerProtocol>();
s0->installProtocolManager ( m0 );
}
QQtBeServerManager::~QQtBeServerManager() {}
QQtBeServerProtocolManager::QQtBeServerProtocolManager ( QObject* parent ) : QQtProtocolManager ( parent ) {}
QQtBeServerProtocolManager::~QQtBeServerProtocolManager() {}
void QQtBeServerProtocolManager::setLocalIpPort ( QString ip, int port )
{
mIP = ip;
mPort = port;
}
QQtProtocol* QQtBeServerProtocolManager::createProtocol()
{
QQtBeServerProtocol* p = ( QQtBeServerProtocol* ) QQtProtocolManager::createProtocol();
p->setLocalIpPort ( mIP, mPort );
return p;
}
QQtBeServerProtocol::QQtBeServerProtocol ( QObject* parent )
: QQtStandardProtocol ( parent ) {}
QQtBeServerProtocol::~QQtBeServerProtocol()
{
}
void QQtBeServerProtocol::setLocalIpPort ( QString ip, int port )
{
mIP = ip;
mPort = port;
}
void QQtBeServerProtocol::sendBeServerMessage()
{
QQtDataSerialization data;
data[CMD_TYPE] = "server_ack";
data[CMD_CONTENT]["ip"] = mIP;
data[CMD_CONTENT]["port"] = mPort;
data.serialize();
p3line() << data[CMD_TYPE].getValue().toString() << mIP << mPort;
sendMessage ( data );
}
void QQtBeServerProtocol::recvMessage ( const QQtDataSerialization& data )
{
QQtDataSerialization ds0 = data;
QString cmd_type = ds0[CMD_TYPE].getValue().toString();
p3line() << cmd_type;
if ( cmd_type == "find_server" )
{
sendBeServerMessage();
}
}
QQtFindServerProtocol::QQtFindServerProtocol ( QObject* parent )
: QQtStandardProtocol ( parent ) {}
QQtFindServerProtocol::~QQtFindServerProtocol()
{
}
void QQtFindServerProtocol::sendFindServerRequest()
{
QQtDataSerialization data;
data[CMD_TYPE] = "find_server";
data.serialize();
p3line() << data[CMD_TYPE].getValue().toString();
sendMessage ( data );
}
void QQtFindServerProtocol::recvMessage ( const QQtDataSerialization& data )
{
QQtDataSerialization ds0 = data;
QString cmd_type = ds0[CMD_TYPE].getValue().toString();
p3line() << cmd_type;
if ( cmd_type == "server_ack" )
{
QQtDictionary& ct0 = ds0[CMD_CONTENT];
mIP = ct0["ip"].getValue().toString();
mPort = ct0["port"].getValue().toInt();
p3line() << mIP << mPort;
emit signalFindServer ( mIP, mPort );
}
}

View File

@ -1,195 +0,0 @@
#ifndef QQTFINDSERVERMANAGER_H
#define QQTFINDSERVERMANAGER_H
#include <QObject>
#include <QHostAddress>
#include <qqtprotocol.h>
#include <qqtstandardprotocol.h>
#include <qqtprotocolmanager.h>
#include <qqtudpclient.h>
#include <qqtudpserver.h>
#include <qqt-local.h>
/**
* @brief The QQtFindServerManager class
*
* CLIENT使用这个类
*/
class QQtFindServerProtocol;
class QQTSHARED_EXPORT QQtFindServerManager : public QObject
{
Q_OBJECT
public:
explicit QQtFindServerManager ( QObject* parent = 0 )
: QObject ( parent ) {}
virtual ~QQtFindServerManager() {}
//准备查找服务器,本地发送、接收信息的端口
void setLocalListenPort ( int port = 4407 );
//准备查找服务器QQtBeServerManager监听的端口
void setServerListenPort ( int port = 4408 );
//客户端主动发起查找只要BeServer存在就能找到。
void sendFindServerRequest();
signals:
void signalFindServer ( QString ip, int port );
protected:
private:
};
/**
* @brief The QQtBeServerManager class
*
* SERVER用
*/
class QQtBeServerProtocol;
class QQtBeServerProtocolManager;
class QQTSHARED_EXPORT QQtBeServerManager : public QObject
{
Q_OBJECT
public:
explicit QQtBeServerManager ( QObject* parent = 0 );
virtual ~QQtBeServerManager();
//准备查找服务器QQtBeServerManager监听的端口
void setServerListenPort ( int port = 4408 ) {
mLocalPort = port;
}
//查找服务器成功告诉客户端的服务器IP、端口。
void setTellClientServerAddress ( QString ip, int port = 5010 );
//主动发起告知客户端。
void sendTellClientServerAddress();
private:
QQtBeServerProtocolManager* m0;
QQtUdpServer* s0;
int mLocalPort;
};
/**
* @brief The QQtBeServerProtocolManager class
*/
class QQTSHARED_EXPORT QQtBeServerProtocolManager : public QQtProtocolManager
{
Q_OBJECT
public:
explicit QQtBeServerProtocolManager ( QObject* parent = 0 );
virtual ~QQtBeServerProtocolManager();
void setLocalIpPort ( QString ip, int port );
private:
QString mIP;
int mPort;
// QQtProtocolManager interface
public:
virtual QQtProtocol* createProtocol() override;
};
enum MsgSecName
{
CMD_TYPE = 0,
CMD_CONTENT,
CMD_MAX
};
/**
* @brief The QQtBeServerProtocol class
* 1.
* 2. IP
* server
*
* cmd_type: "find_server", "server_ack"
*
* [0] "find_server"
* ...
*
* [0] "server_ack"
* [1]
* ["ip"]
* ["port"]
*/
class QQTSHARED_EXPORT QQtBeServerProtocol : public QQtStandardProtocol
{
Q_OBJECT
public:
explicit QQtBeServerProtocol ( QObject* parent = 0 );
virtual ~QQtBeServerProtocol();
void setLocalIpPort ( QString ip, int port );
void sendBeServerMessage();
protected:
private:
signals:
// QQtStandardProtocol interface
public:
virtual void recvMessage ( const QQtDataSerialization& data ) override;
private:
QString mIP;
int mPort;
};
/**
* @brief The QQtFindServerProtocol class
* 1.
* 2. IP
* client
*
* cmd_type
* [0] "find_server", "server_ack"
*
* [0] "find_server"
* ...
*
* [0] "server_ack"
* [1]
* ["ip"]
* ["port"]
*/
class QQTSHARED_EXPORT QQtFindServerProtocol : public QQtStandardProtocol
{
Q_OBJECT
public:
explicit QQtFindServerProtocol ( QObject* parent = 0 );
virtual ~QQtFindServerProtocol();
void sendFindServerRequest();
protected:
private:
signals:
void signalFindServer ( QString ip, int port );
// QQtStandardProtocol interface
public:
virtual void recvMessage ( const QQtDataSerialization& data ) override;
private:
QString mIP;
int mPort;
};
#endif // QQTFINDSERVERMANAGER_H