PDA

View Full Version : QT Socket programming



praveen1
6th September 2012, 17:47
i am receiving large structure (sizeof structure is around 130024) in a QT server programme from non-qt client. But it receives only 50176 bytes out of 130024 bytes sent from client. i am using qsocket.read() at qt server. i had tried sending of the struct in slices of 1460 bytes and but still i am able to receive only 50176 bytes at my QT programme. The size of receiving buffer is 130024 bytes.

QTcpSocket qsocket ;
if (!qsocket.setSocketDescriptor(socketDescriptor))
{
emit error(qsocket.error());
return;
}
QHostAddress clientt_adrr = qsocket.peerAddress();
QString client_adrr = clientt_adrr.toString();
while(1)
{ if(qsocket.bytesAvailable())
{
data_sz1 = qsocket.read(Rawbuf, sizeof(struct Result));
}
}

size of struct Result is 130024 bytes.
Please help me to resolve this problem.
thanks..

yeye_olive
6th September 2012, 21:57
Why did you create a new thread with the same question as the one you started on August 24th?

I replied to your first thread. It seems that you never bothered reading the page to which I linked there. If you had, you would know that you are dealing with the so-called "framing problem".

Your code cannot work because the socket is meant to be used asynchronously and you have to return to the event loop and wait for the socket to emit its readyRead() signal. You may also go for a synchronous approach, but then you have to call waitForReadyRead() to wait until data is available.

I suggest you read the documentation for QAbstractSocket and check out the network examples mentioned there.

Last but not least, please show some interest in solving your own problem by at least trying to follow the advice others give you. Spamming the forum until someone posts a complete solution is a path to disappointment.

praveen1
7th September 2012, 09:28
sorry for this...
I thought i may not get reply if i'll use the old thread..that's why i created a new thread..
Thanks for your solution...
when i am using waitForReadyRead() its working...