I am making simple client server program using QTcpServer, QTcpSocket with out using thread,in fedora. I want to make my application, independent of sequence of what is running first, client or server.My application is running well when I start server first, but I am not getting any way to make client wait, while server is not start and connect with serve as server start. I used waitForConnection() but it is not helping. Please give some suggestions.
TcpClient::TcpClient(QWidget *parent) : QMainWindow(parent),
ui(new Ui::TcpClient)
{
ui->setupUi(this);
tcpSocket= new QTcpSocket(this);
tcpSocket->connectToHost(QHostAddress::LocalHost,6178);
connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendRequest()));
connect(tcpSocket, SIGNAL(disconnected()),this, SLOT(connectionClosedByServer()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),this, SLOT(error()));
.
.
..
}
void TcpClient::error()
{
ui->lStatus->setText(tcpSocket->errorString());
closeConnection();
tcpSocket->connectToHost(QHostAddress::LocalHost,6178);
}