blob: 0438fb42023d5db6e243a3fb52a0749441a0b536 (
plain) (
tree)
|
|
#include "listenserver.h"
#include "client.h"
#include <QSslSocket>
#define MAX_CLIENTS 50
/**
* Initialize listenServer to listen on specific port.
* And connect Signal newConnection() with Slot newClientConnection().
* @param port
*/
ListenServer::ListenServer(quint16 port)
{
if (!_server.listen(QHostAddress::AnyIPv4, port) || !_server.isListening())
qFatal("Cannot bind to TCP port %d (incoming SSL clients)", int(port));
connect(&_server, SIGNAL(newConnection()), this, SLOT(newClientConnection()));
}
ListenServer::~ListenServer()
{
_server.close();
}
/*
* Slots
*/
/**
* Handle new client connection.
* If there are not already to much clients, emit signal newClient().
*/
void ListenServer::newClientConnection()
{
QTcpSocket* sock;
while ((sock = _server.nextPendingConnection()) != nullptr) {
Client* client = new Client(sock); // TODO: what happens with disconnected clients
emit newClient(client);
}
}
|