fixed socket not closing

This commit is contained in:
Anselme 2015-09-18 20:32:11 +02:00
parent bb2a6db5aa
commit bfd3119beb
2 changed files with 16 additions and 0 deletions

View File

@ -44,6 +44,17 @@ void Server::update()
clients[i]->sendFull(clients, i); clients[i]->sendFull(clients, i);
} }
Server::~Server()
{
if(server->isListening())
server->close();
server->deleteLater();
timer->stop();
delete timer;
for(int i=0; i<clients.size(); ++i)
delete clients[i];
}
void Server::on_newConnection() void Server::on_newConnection()
{ {
QTcpSocket* socket = server->nextPendingConnection(); QTcpSocket* socket = server->nextPendingConnection();
@ -79,7 +90,11 @@ Client::Client(QTcpSocket* mySocket)
Client::~Client() Client::~Client()
{ {
if(socket != NULL) if(socket != NULL)
{
if(socket->isOpen())
socket->close();
socket->deleteLater(); socket->deleteLater();
}
} }
void Client::on_readyRead() void Client::on_readyRead()

View File

@ -15,6 +15,7 @@ class Server : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit Server(unsigned short port = 20202, QObject *parent = 0); explicit Server(unsigned short port = 20202, QObject *parent = 0);
~Server();
QTcpServer* server; QTcpServer* server;
QTimer* timer; QTimer* timer;
std::vector<Client*> clients; std::vector<Client*> clients;