Debug() << QString("Resolved %1 to %2").arg(host).arg(ip);
}
void Client::connected()
{
qDebug() << "Connected!";
// Send our name
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << myName;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
tcpSocket->write(block);
}
void Client::disconnected()
{
qDebug() << "Disconnected!";
}
void Client::bytesWritten(qint64 bytes)
{
qDebug() << QString("Bytes written: %1").arg(bytes);
}
void Client::readyRead()
{
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_0);
// Read the data length
if (blockSize == 0) {
if (tcpSocket->bytesAvailable() < (int)sizeof(quint16)) {
return;
}
in >> blockSize;
}
// Read the data
if (tcpSocket->bytesAvailable() < blockSize) {
return;
}
QString otherName;
QString message;
in >> otherName >> message;
qDebug() << QString("Received message from %1: %2").arg(otherName).arg(message);
// Reset the data length
blockSize = 0;
}