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

55 lines
1.4 KiB
C++
Raw Normal View History

2018-04-23 10:00:09 +08:00
#include "qqtclientprotocol.h"
QDebug& operator << ( QDebug& dbg, const QQtClientMessage& msg )
{
//这里打印一下,报文里面到底有什么信息,
//一般到这里的都是被解析好的message。
dbg.nospace() << "{" << hex << msg.getBSize() << "}";
return dbg.space();
}
QQtClientProtocol* QQtClientConnectionInstance ( QObject* parent )
{
static QQtClientProtocol* p0 = NULL;
static QQtTcpClient* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtClientProtocol ( parent );
s0 = new QQtTcpClient ( parent );
s0->installProtocol ( p0 );
QStringList ip;
2018-04-27 20:54:40 +08:00
ip << "192.168.0.100";
2018-04-28 23:53:19 +08:00
s0->setServerIPAddress ( ip );
s0->setServerPort ( 8001 );
2018-04-23 10:00:09 +08:00
2018-04-28 23:53:19 +08:00
s0->sendConnectToHost();
2018-04-23 10:00:09 +08:00
}
return p0;
}
2018-04-29 23:14:13 +08:00
#include "qqtudpclient.h"
QQtClientProtocol* QQtClientUdpConnectionInstance ( QObject* parent )
{
static QQtClientProtocol* p0 = NULL;
static QQtUdpClient* s0 = NULL;
if ( !p0 && !s0 )
{
p0 = new QQtClientProtocol ( parent );
s0 = new QQtUdpClient ( parent );
s0->installProtocol ( p0 );
QStringList ip;
ip << "192.168.0.102";
s0->setServer ( ip[0], 8001 );
//我接收服务器消息,所以需要绑定本地端口
s0->bind ( 8500 );
}
return p0;
}