void server::incomingConnection(qintptr socketDescriptor) {
qDebug() << "incoming connection";
connection* new_connection = new connection(this);
new_connection->set_socket_descriptor(socketDescriptor);
connect(new_connection, SIGNAL(ready_read()), this, SLOT(ready_read()));
connect(new_connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
emit signal_new_connection(new_connection);
}
server class is inherited from QTcpServer, and connection class has a QTcpSocket as member and some info about user who want to connect( name, ip, id...)
my problem is that i don't know nothing about new_connection. i need to know who is connecting with server. for this reason i want to connect-back but how? is there any way? or must wait till i receive data(greeting message) from connected socket(user) ?
I've just accidentaly bumped into this old thread having the same problem. And I just found the solution, so I decided to post here in case someone has similar problem.
To get actual
QTcpSocket
(the one which emittedreadyRead()
signal), you can useQObject::sender()
method, e.g.: