I used both the methods as you mentioned. In the asynchronous method I tried, the code looked like this -
clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
connect( clientConnection, SIGNAL(readyRead()),
this, SLOT(readClient()) );
clientConnection = tcpServer->nextPendingConnection();
connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));
connect( clientConnection, SIGNAL(readyRead()),
this, SLOT(readClient()) );
To copy to clipboard, switch view to plain text mode
where the readClient() slot implementation is as shown -
void serverwindow::readClient()
{
//pass this socket to a new thread which send some data to client
}
void serverwindow::readClient()
{
QTcpSocket* clientSocket = (QTcpSocket*)sender();
//pass this socket to a new thread which send some data to client
}
To copy to clipboard, switch view to plain text mode
Here as I obtain some data on socket, I used to spawn a new thread with the socket reference as a parameter to the thread. This caused huge problems because that socket reference could not be "moved" to another thread. So this was the issue I faced with the asynchronous method.
So I used th synchronous method with waitForReadyRead() method with some parameter ( which is not the way code should be written; I understand ).
Certainly I know, the asynch method is better, but I could not find a solution to the above problem . If you could provide some solution to this, I would be happy to incorporate into my code.
Bookmarks