i' sorry .
this is the original code :
a part of simplechatclient.cpp :
void SimpleChatClient::sendMessage()
{
// "<nick> message\n"
socket->write("<" + nick->text().toLatin1() + "> " + message->text().toLatin1() + "\n");
message->clear();
}
void SimpleChatClient::receiveMessage()
{
// missing some checks for returns values for the sake of simplicity
qint64 bytes = buffer->write(socket->readAll());
// go back as many bytes as we just wrote so that it can be read
buffer->seek(buffer->pos() - bytes);
// read only full lines, line by line
while (buffer->canReadLine())
{
chat->append(line.simplified());
}
}
void SimpleChatClient::sendMessage()
{
// "<nick> message\n"
socket->write("<" + nick->text().toLatin1() + "> " + message->text().toLatin1() + "\n");
message->clear();
}
void SimpleChatClient::receiveMessage()
{
// missing some checks for returns values for the sake of simplicity
qint64 bytes = buffer->write(socket->readAll());
// go back as many bytes as we just wrote so that it can be read
buffer->seek(buffer->pos() - bytes);
// read only full lines, line by line
while (buffer->canReadLine())
{
QString line = buffer->readLine();
chat->append(line.simplified());
}
}
To copy to clipboard, switch view to plain text mode
a part of simplechatsever.cpp :
void SimpleChatServer::receiveMessage()
{
QTcpSocket* socket
= static_cast<QTcpSocket
*>
(sender
());
QBuffer* buffer
= buffers.
value(socket
);
// missing some checks for returns values for the sake of simplicity
qint64 bytes = buffer->write(socket->readAll());
// go back as many bytes as we just wrote so that it can be read
buffer->seek(buffer->pos() - bytes);
// read only full lines, line by line
while (buffer->canReadLine())
{
{
connection->write(line);
}
}
}
void SimpleChatServer::receiveMessage()
{
QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
QBuffer* buffer = buffers.value(socket);
// missing some checks for returns values for the sake of simplicity
qint64 bytes = buffer->write(socket->readAll());
// go back as many bytes as we just wrote so that it can be read
buffer->seek(buffer->pos() - bytes);
// read only full lines, line by line
while (buffer->canReadLine())
{
QByteArray line = buffer->readLine();
foreach (QTcpSocket* connection, connections)
{
connection->write(line);
}
}
}
To copy to clipboard, switch view to plain text mode
I had fix only at these methods And declare quint32 blockSize in the header file.
Bookmarks