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

74 lines
2.0 KiB
C++
Raw Normal View History

2018-04-23 20:37:21 +08:00
#include "qqtserverprotocolmanager.h"
2018-04-22 23:00:42 +08:00
2018-04-29 12:36:11 +08:00
QQtServerProtocolManager::QQtServerProtocolManager ( QObject* parent ) : QQtProtocolManager ( parent )
2018-04-22 23:00:42 +08:00
{
}
2018-04-29 23:13:40 +08:00
#include <qqttcpserver.h>
2018-04-29 12:36:11 +08:00
QQtServerProtocolManager* QQtServerInstance ( QObject* parent )
2018-04-22 23:00:42 +08:00
{
2018-04-29 12:36:11 +08:00
static QQtServerProtocolManager* m0 = 0;
2018-04-22 23:00:42 +08:00
if ( !m0 )
{
//创建Protocol管理者
2018-04-29 12:36:11 +08:00
m0 = new QQtServerProtocolManager ( parent );
2018-04-22 23:00:42 +08:00
//注册我实现的Protocol
2018-04-29 12:36:11 +08:00
m0->registerProtocol<QQtServerProtocol> ( );
2018-04-22 23:00:42 +08:00
//初始化Protocol管理者完成。
}
static QQtTcpServer* s0 = 0;
if ( !s0 )
{
//新建服务器
s0 = new QQtTcpServer ( parent );
//安装协议管理者
s0->installProtocolManager ( m0 );
//开始监听
s0->listen ( QHostAddress::Any, 8001 );
//服务器初始化完成。
}
//等待客户端发消息过来Protocol就处理了去业务层看看。
return m0;
}
2018-04-23 16:45:54 +08:00
2018-04-23 20:37:21 +08:00
QDebug& operator << ( QDebug& dbg, const QQtServerMessage& msg )
2018-04-23 16:45:54 +08:00
{
dbg << msg.getASize() << msg.getACmd() << msg.getAData();
dbg << msg.getBSize() << msg.getBCmd() << msg.getBData();
return dbg;
}
2018-04-29 23:13:40 +08:00
#include "qqtudpserver.h"
QQtServerProtocolManager* QQtServer2Instance ( QObject* parent )
{
static QQtServerProtocolManager* m0 = 0;
if ( !m0 )
{
//创建Protocol管理者
m0 = new QQtServerProtocolManager ( parent );
//注册我实现的Protocol
m0->registerProtocol<QQtServerProtocol> ( );
//初始化Protocol管理者完成。
}
static QQtUdpServer* s0 = 0;
if ( !s0 )
{
//新建服务器
s0 = new QQtUdpServer ( parent );
//安装协议管理者
s0->installProtocolManager ( m0 );
//开始监听
2018-04-29 23:44:22 +08:00
s0->bind ( QHostAddress::Any, 8001 );
2018-04-29 23:13:40 +08:00
//服务器初始化完成。
}
//等待客户端发消息过来Protocol就处理了去业务层看看。
return m0;
}