2018-04-23 20:25:18 +08:00
|
|
|
|
#include "qqtserver2protocolmanager.h"
|
|
|
|
|
|
|
|
|
|
QDebug& operator << ( QDebug& dbg, const QQtClient2Message& msg )
|
|
|
|
|
{
|
|
|
|
|
//这里打印一下,报文里面到底有什么信息,
|
|
|
|
|
//一般到这里的,都是被解析好的message。
|
|
|
|
|
|
|
|
|
|
dbg.nospace() << "{" << hex << msg.size() << "}";
|
|
|
|
|
return dbg.space();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 20:37:21 +08:00
|
|
|
|
QQtProtocolManager* QQtServer2ConnectionInstance ( QObject* parent )
|
2018-04-23 20:25:18 +08:00
|
|
|
|
{
|
2018-04-23 21:04:58 +08:00
|
|
|
|
static QQtProtocolManager* m0 = NULL;
|
2018-04-23 20:25:18 +08:00
|
|
|
|
if ( !m0 )
|
|
|
|
|
{
|
|
|
|
|
//创建Protocol管理者
|
|
|
|
|
m0 = new QQtProtocolManager ( parent );
|
|
|
|
|
//注册我实现的Protocol
|
2018-04-24 01:31:28 +08:00
|
|
|
|
m0->registerProtocol<QQtServer2Protocol> ( );
|
2018-04-23 20:25:18 +08:00
|
|
|
|
//初始化Protocol管理者完成。
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 21:04:58 +08:00
|
|
|
|
static QQtTcpServer* s0 = NULL;
|
2018-04-23 20:25:18 +08:00
|
|
|
|
if ( !s0 )
|
|
|
|
|
{
|
|
|
|
|
//新建服务器
|
|
|
|
|
s0 = new QQtTcpServer ( parent );
|
|
|
|
|
//安装协议管理者
|
|
|
|
|
s0->installProtocolManager ( m0 );
|
|
|
|
|
//开始监听
|
|
|
|
|
s0->listen ( QHostAddress::Any, 8500 );
|
|
|
|
|
//服务器初始化完成。
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//等待客户端发消息过来,Protocol就处理了,去业务层看看。
|
|
|
|
|
return m0;
|
|
|
|
|
}
|