QTcpServer/Socket Bidrirectional Communication
Dear All,
Am working on Server and Socket project. I want both of the server and socket talk to each other, meaning writing and reading! However, its not working! I tried the socket writing to the server, and it works great! But the server writing to the client is not working!! wat i am missing here :confused:
Server Code:
Code:
connect(&m_TcpServer8000, SIGNAL(newConnection()), this, SLOT(acceptLegacyDLIConnection()));
//here i define the signal slot of the server writing to the socket
connect(timer, SIGNAL(timeout()), this, SLOT (handleWrite()));
}
ServerOne::~ServerOne() {
}
//accepts the incoming connection
void ServerOne::acceptLegacyDLIConnection(){
m_TcpSocket8000 = m_TcpServer8000.nextPendingConnection();
connect(m_TcpSocket8000, SIGNAL(readyRead()), this, SLOT(handleRead()));
timer->start(4000);
}
//handles the incoming data from the socket
void ServerOne::handleRead(){
}
//handles the write to the client socket
void ServerOne::handleWrite(){
m_TcpSocket8000->write("In the server and writing to the client..");
qDebug() << "writing..";
}
Client Side:
Code:
connect(client8000, SIGNAL(connected()), this, SLOT(handleWrite()));
connect(client8000, SIGNAL(readyRead()), this, SLOT(handleRead()));
}
Client::~Client() {
}
//connects the socket to the server and starts timer to send continous msgs to server
void Client
::connectToServer(QString address, quint16 port
) { client8000->connectToHost(addr, port);
connect(timer, SIGNAL(timeout()), this, SLOT(handleWrite()));
timer->start(2000);
}
// handles the writing to server
void Client::handleWrite() {
}
//handles the incoming data from server
void Client::handleRead() {
char buffer [1024] = {0};
client8000->read(buffer, client8000->bytesAvailable());
cout << buffer << endl;
}
Re: QTcpServer/Socket Bidrirectional Communication
Please provide a minimum compilable example reproducing the problem.