PDA

View Full Version : QTcpServer::hasPendingConnections () - socket creation issue



pdoria
5th September 2008, 11:19
Dear All,

From the fine QT manual:
"This virtual function is called by QTcpServer when a new connection is available. The socketDescriptor argument is the native socket descriptor for the accepted connection.
The base implementation creates a QTcpSocket, sets the socket descriptor and then stores the QTcpSocket in an internal list of pending connections. Finally newConnection() is emitted.
Reimplement this function to alter the server's behavior when a connection is available."

Now the question is:
reimplementing the function prevents the creation of a QTcpSocket? -- meaning that I'm only interested in the socketDescriptor for passing it into another thread and creating the socket there...

Regards,
Pedro Doria Meunier

kingslee
5th September 2008, 12:36
I didnt get u fully.

here is how u do

u have to modify the incomingconnection(int socketDescriptor).

create a class:


class CTest: public QTcpServer
{
Q_OBJECT

public:
CTest(QObject *parent = 0);

protected:
void incomingConnection(int socketDescriptor);
}

From ur main application, derive the pointer or object of this class and then start server by listening.

Then u will get socketDescriptor everytime a new client connect.

Hope this helps.