How block/cancel specific IP adress
-
I have a QtTcpServer and more than one client .... I know the right ip adress to accept and would block or non accept other .... so I try in these way on my server side:
/* in mainwindows */ connect(server, SIGNAL(newConnection()), this, SLOT(new_con())); /* after */ void MainWindow::new_con() { client = new QTcpSocket(); client = server->nextPendingConnection(); qDebug() << "connesso nuovo client...." << client->peerAddress().toString(); QString conClient = client->peerAddress().toString(); if(conClient == peerF){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket); qDebug() << "client F..." ;} if(conClient == peerBR){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket1); qDebug() << "client BR...." ;} if(conClient == peerB){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket2); qDebug() << "client B...." ;} if((conClient == peerF) || (conClient == peerBR) || (conClient == peerB)){ connect(client, &QTcpSocket::disconnected,this, &MainWindow::discardSocket); connect(client, &QTcpSocket::errorOccurred, this, &MainWindow::sokError); connect(client, &QTcpSocket::connected, this, &MainWindow::sokConnSTATE); connect(client, &QTcpSocket::disconnected, this, &MainWindow::sokDiscSTATE); connect(client, &QTcpSocket::stateChanged, this, &MainWindow::sokState); client->setSocketOption(QAbstractSocket:: KeepAliveOption, 1); } else{client->deleteLater(); qDebug() << "discharge socket";} /*....... other stuff */ }
Any How when unappropriate ip adress try to connect my app crash .... appreciate any suggest for reach my goal.
regards
-
I have a QtTcpServer and more than one client .... I know the right ip adress to accept and would block or non accept other .... so I try in these way on my server side:
/* in mainwindows */ connect(server, SIGNAL(newConnection()), this, SLOT(new_con())); /* after */ void MainWindow::new_con() { client = new QTcpSocket(); client = server->nextPendingConnection(); qDebug() << "connesso nuovo client...." << client->peerAddress().toString(); QString conClient = client->peerAddress().toString(); if(conClient == peerF){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket); qDebug() << "client F..." ;} if(conClient == peerBR){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket1); qDebug() << "client BR...." ;} if(conClient == peerB){ connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket2); qDebug() << "client B...." ;} if((conClient == peerF) || (conClient == peerBR) || (conClient == peerB)){ connect(client, &QTcpSocket::disconnected,this, &MainWindow::discardSocket); connect(client, &QTcpSocket::errorOccurred, this, &MainWindow::sokError); connect(client, &QTcpSocket::connected, this, &MainWindow::sokConnSTATE); connect(client, &QTcpSocket::disconnected, this, &MainWindow::sokDiscSTATE); connect(client, &QTcpSocket::stateChanged, this, &MainWindow::sokState); client->setSocketOption(QAbstractSocket:: KeepAliveOption, 1); } else{client->deleteLater(); qDebug() << "discharge socket";} /*....... other stuff */ }
Any How when unappropriate ip adress try to connect my app crash .... appreciate any suggest for reach my goal.
regards
@gfxx said in How block/cancel specific IP adress:
client = new QTcpSocket(); client = server->nextPendingConnection();
Hello memleak...
Any How when unappropriate ip adress try to connect my app crash
Then use a debugger to find out where it crashes, your code above does not create a crash, just a memleak as shown above.
-
@gfxx said in How block/cancel specific IP adress:
client = new QTcpSocket(); client = server->nextPendingConnection();
Hello memleak...
Any How when unappropriate ip adress try to connect my app crash
Then use a debugger to find out where it crashes, your code above does not create a crash, just a memleak as shown above.
@Christian-Ehrlicher ok understand .... but my code is ok for close connection when non desired IP adress try to connect? These is a right manner?
Need di dischard/disconnect every undesired ip adress ....
/*peerF, peerBR, peerB was QString with ip adress needed*/ QString conClient = client->peerAddress().toString(); if((conClient == peerF) || (conClient == peerBR) || (conClient == peerB)){ /* .... other code. ... */ } else{client->deleteLater(); qDebug() << "discharge socket";}
About memory leak :
/*client = new QTcpSocket();*/ client = server->nextPendingConnection();
these can be?
-
@Christian-Ehrlicher ok understand .... but my code is ok for close connection when non desired IP adress try to connect? These is a right manner?
Need di dischard/disconnect every undesired ip adress ....
/*peerF, peerBR, peerB was QString with ip adress needed*/ QString conClient = client->peerAddress().toString(); if((conClient == peerF) || (conClient == peerBR) || (conClient == peerB)){ /* .... other code. ... */ } else{client->deleteLater(); qDebug() << "discharge socket";}
About memory leak :
/*client = new QTcpSocket();*/ client = server->nextPendingConnection();
these can be?
@gfxx said in How block/cancel specific IP adress:
but my code is ok for close connection when non desired IP adress try to connect?
Yes
these can be?
correct
-
@gfxx said in How block/cancel specific IP adress:
but my code is ok for close connection when non desired IP adress try to connect?
Yes
these can be?
correct
@Christian-Ehrlicher Real Thanks ... and happy sunday.