I want to use setMaxPendingConnections
in my application. I've tried that code:
MainCLass::MainCLass(QObject *parent) : QObject(parent)
{
this->server = new QTcpServer(this);
server->setMaxPendingConnections(2);
QObject::connect(this->server, SIGNAL(newConnection()), this, SLOT(newuser()));
if (!this->server->listen(QHostAddress::Any, 33333)) {
qDebug() << "Error create server!";
}
}
void MainCLass::newuser()
{
qDebug() << "New client!";
QTcpSocket* clientSocket=server->nextPendingConnection();
clientSocket->write("Hello!");
qDebug() << "Max connect?" << this->server->hasPendingConnections();
}
But it does not work. More than 2 clients is able to connected in my server. What's wrong? Where is mistake? I use Qt5. Tried on Windows 7 and Ubuntu 12
nextPendingConnection
, it's not pending any more and the pending connections counter gets decreased. – peppe Mar 11 '16 at 0:54nextPendingConnection
if you're already handling enough clients. – peppe Mar 11 '16 at 10:49