void MyServer::sendToClient(/*QTcpSocket*/ QIODevice *pSocket, Message *toSend){ QByteArray arrBlock; QDataStream out (&arrBlock, QIODevice::WriteOnly); out.setVersion (QDataStream::Qt_4_8); out << quint16 (0) << QTime::currentTime () << *toSend; out.device ()->seek (0); out << quint16 (arrBlock.size ()- sizeof (quint16)); pSocket->write (arrBlock); pSocket->waitForBytesWritten (100); QThread::msleep (50);}
C++ (Qt)void MyServer::sendToClient(/*QTcpSocket*/ QIODevice *pSocket, Message *toSend){ QByteArray arrBlock; { QDataStream out (&arrBlock, QIODevice::WriteOnly); out.setVersion (QDataStream::Qt_4_8); out << quint16 (0) << QTime::currentTime () << *toSend; out.device ()->seek (0); out << quint16 (arrBlock.size ()- sizeof (quint16)); } qDebug() << arrBlock.size(); pSocket->write (arrBlock); pSocket->waitForBytesWritten (100);}