i am working on a project that requires tcp communication between a \"master\" application and a number of \"servants\". (the project is in c++ and i am also using qt)
to build a server in Qt is very simple. you have to derive QTcpServer and implement some methods or slot. This is valid for the clients too. Derive QTcpSocket and you will have your client.
in example, to detect a client incoming you implement virtual void incomingConnection ( int socketDescriptor ) .so in your case you can save clients incoming in a map(a map because every client will have his own id).
in both server and client you will probably want to implement readyRead() slot. this slot do the communication thing that you want. in fact inside this slot the server can receive and send to client messages and vice-versa.
this is a tipical readyread :
void Client::readyRead() {
while (this->canReadLine()) {
// here you get the message from the server
const QString& line = QString::fromUtf8(this->readLine()).trimmed();
}
}
this is how to send messages:
void Client::sendMessage(const QString& message) {
this->write(message.toUtf8());
this->write("\n");
}
That s all!