mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
53 lines
1.1 KiB
C++
Executable File
53 lines
1.1 KiB
C++
Executable File
#include "qqtserver.h"
|
|
#include "qqtdefine.h"
|
|
|
|
|
|
QQTServer::QQTServer(QObject *parent) :
|
|
QTcpServer(parent)
|
|
{
|
|
}
|
|
|
|
QQTServer::~QQTServer()
|
|
{
|
|
close();
|
|
}
|
|
|
|
void QQTServer::incomingConnection(int handle)
|
|
{
|
|
QQTClient* clientSocket = new QQTClient(this);
|
|
clientSocket->setSocketDescriptor(handle);
|
|
connect(clientSocket, SIGNAL(disconnected()), clientSocket, SLOT(deleteLater()));
|
|
clientSocket->installProtocol(m_protocol);
|
|
}
|
|
|
|
void QQTServer::installProtocol(QQTProtocol *stack)
|
|
{
|
|
if(m_protocol)
|
|
return;
|
|
|
|
m_protocol = stack;
|
|
connect(m_protocol, SIGNAL(write(const QByteArray&)), this, SLOT(write(const QByteArray&)));
|
|
}
|
|
|
|
void QQTServer::uninstallProtocol(QQTProtocol *stack)
|
|
{
|
|
if(!m_protocol)
|
|
return;
|
|
|
|
disconnect(m_protocol, SIGNAL(write(const QByteArray&)), this, SLOT(write(const QByteArray&)));
|
|
m_protocol = NULL;
|
|
}
|
|
|
|
QQTProtocol *QQTServer::installedProtocol()
|
|
{
|
|
return m_protocol;
|
|
}
|
|
|
|
QQTServer *QQTSingleServer(QObject *parent)
|
|
{
|
|
static QQTServer* s = new QQTServer(parent);
|
|
s->listen(QHostAddress::Any, 8000);
|
|
return s;
|
|
}
|
|
|