Dear All,
I need to send data to the server, which may have headers, based on the header type. Data will be sent to respective class or lineedit or text edit. But in my client application the entire data is sent across the socket. But, where as in server side I need to check the headers then handle or processs the data.
Void Client:: Write()
{
{
QString linedata
=ui
->lineedit
->text
();
DATA.append(linedata);
socket.write(DATA.toUf8.constdata());
}
QString linedata
=ui
->lineedit_1
->text
();
DATA.append(linedata);
socket.write(DATA.toUf8.constdata());
}
}
Void Client:: Write()
{
{
QByteArray DATA="001";
QString linedata=ui->lineedit->text();
DATA.append(linedata);
socket.write(DATA.toUf8.constdata());
}
{QByteArray DATA="002";
QString linedata=ui->lineedit_1->text();
DATA.append(linedata);
socket.write(DATA.toUf8.constdata());
}
}
To copy to clipboard, switch view to plain text mode
Void Server::read()
{
{
QTcpSocket *socket
= qobject_cast<QTcpSocket
*>
( sender
() );
{
{
if(buffer.startsWith("001"))
qDebug()<<buf;
buff=buffer.mid(3)
Lineedit->setText(buff)
qDebug()<<buf;
}
{
if(buffer.startsWith("002"))
buff=buffer.mid(3)
Lineedit->setText(buff)
}
Void Server::read()
{
{
QTcpSocket *socket = qobject_cast<QTcpSocket*>( sender() );
{
QByteArray buffer= socket->readLine();
{
if(buffer.startsWith("001"))
QByteArray buf=buffer;
qDebug()<<buf;
buff=buffer.mid(3)
Lineedit->setText(buff)
qDebug()<<buf;
}
{
if(buffer.startsWith("002"))
QByteArray buf=buffer;
buff=buffer.mid(3)
Lineedit->setText(buff)
}
To copy to clipboard, switch view to plain text mode
Here the problem is when socket is read at server side. In QDebug im getting complete data like "001hello002hi"
in the Lineedit of server complete line is printed (hello002hi) instead of giving only "hello" and actually by checking with "002" next lineedit_2 as "hi" msg to lineedit_2. How can i address this.
Bookmarks