Skip to content

Instantly share code, notes, and snippets.

@oppahero
Created November 9, 2018 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oppahero/942b8af55850e16bf2c39025c637fb00 to your computer and use it in GitHub Desktop.
Save oppahero/942b8af55850e16bf2c39025c637fb00 to your computer and use it in GitHub Desktop.
void Server::sendTextToAll(QString text,ClientThread* except){
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_8);
out << (quint32)0 << text;
out.device()->seek(0);
out << (quint32)(block.size() - sizeof(quint32));
qDebug() << "block.size() = " << block.size();
qint64 x = 0;
foreach(ClientThread* eachClient,clientThreadList){
if(except != NULL && eachClient == except)
continue;
x = 0;
while(x < block.size()){
qint64 y = eachClient->getTcpSocket()->write(block);
x+=y;
qDebug() << eachClient->getUsername()<< "/sent" << x ;
}
qDebug() << "-----";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment