I'm writing Client/Server communication system on Qt. I'm using QTcpServer and QtcpSocket. I'm sending some information from client side but how can I return value from server?
Client Side
QTcpSocket *socket = new QTcpSocket(this);
socket->connectToHost("MyHost", "MyPort");
socket->write("Hello from Client...");
Server Side
QtSimpleServer::QtSimpleServer(QObject *parent) : QTcpServer(parent)
{
if (listen(QHostAddress::Any, "MyPort"))
{
qDebug() << "Listening...";
}
else
{
qDebug() << "Error while listening... " << errorString();
}
}
void QtSimpleServer::incomingConnection(int handle)
{
QTcpSocket *socket = new QTcpSocket();
socket->setSocketDescriptor(handle);
connect (socket, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
}
void QtSimpleServer::onReadyRead()
{
QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
qDebug() << socket->readAll();
socket->disconnectFromHost();
socket->close();
socket->deleteLater();
}