hi there
i am designing a C/S application. The client is supposed to query the server sending some data (basically just one opcode which describes what the server has do. if the server reply 'busy', the client will retry for a certain number of times, if the server reply available, the server will wait for a message containing the status of the task the server have been asked for

since the fortune client/server example did not seem suited fort this (the cleint just connect to the server but does not transmit anything), i am doing something based on this example

http://doc.qt.nokia.com/4.7-snapshot...ialog-cpp.html

The server connects immediately as soon as the constructor is invoked and the newConncection signal is connected to the acceptConnection() slot (see dialog example
Qt Code:
  1. tcpServer = new QTcpServer(this);
  2. connect(tcpServer, SIGNAL(newConnection()), this, SLOT(acceptConnection()));
  3. ....
  4. void ecmqMfgServer::acceptConnection()
  5. {
  6. tcpServerConnection = tcpServer->nextPendingConnection();
  7. connect(tcpServerConnection, SIGNAL(readyRead()), this, SLOT(readCli2SvrMsg()));
  8. connect(tcpServerConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
  9. tcpServer->close(); // should i close EVERY time
  10. }
To copy to clipboard, switch view to plain text mode 
the acceptConnection code just connect the readyRead signal to my 'read' method. First question is: why the tcpServer must be 'closed' here ?
then, after getting an available ipAddress and port, i ask the server to listen and notify the outcome
Qt Code:
  1. if (!tcpServer->listen(HostAddress, this->ipPort) &&
  2. !tcpServer->listen(HostAddress, this->ipPort))
  3. ...
To copy to clipboard, switch view to plain text mode 
finally my read method
Qt Code:
  1. void ecmqMfgServer::readCli2SvrMsg()
  2. {
  3. qint16 bytesAvail;
  4. bytesAvail= tcpServerConnection->bytesAvailable();
  5. const QString msg = tr("bytes received : ")
  6. + QString("%5").arg(bytesAvail)
  7. + tr(" on ") + QDateTime::currentDateTime().toString(Qt::ISODate);
  8. ui.plainTextEditLog->appendPlainText(msg);
  9.  
  10. QByteArray block;
  11. QDataStream in(&block, QIODevice::ReadOnly);;
  12. in.setVersion(QDataStream::Qt_4_1);
  13. block.resize(bytesAvail);
  14. in>>block;
  15.  
  16. return;
  17. }
To copy to clipboard, switch view to plain text mode 

I then experience the following strange behavior:
- the first time my client send 2 bytes to the server, i can see 2 received bytes in my output
- if the client attempt to send again the same bytes nothing is reported as 'received'

i am currently debugging this issue but cannot get rid of this. i feel there is something basically wrong in this approach

any help is appreciated (have mercy on the newbie, please)