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);
}
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()
{
QTcpSocket* socket = server->nextPendingConnection();
@ -79,8 +90,12 @@ Client::Client(QTcpSocket* mySocket)
Client::~Client()
{
if(socket != NULL)
{
if(socket->isOpen())
socket->close();
socket->deleteLater();
}
}
void Client::on_readyRead()
{

View File

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