PDA

View Full Version : QT Network Performance.



csvivek
3rd April 2008, 14:24
Hi,
I am developing a realtime application.
I have a server that is written in C and this pumps data to the server at the maximum possible rate.
i tried using Qt sockets to receive the data from the server. i used readyread signal to read the data from the socket and display. The code is given below.

i find some data loss out of the 1000 messge sent from server to the client, i receive only 967.
but the same when i receive it with C sockets i am able to receive all the 1000 data from the server. can anyone tell where the problem is?
if not please tell the way to improve the performance. i tried using Qt::AutoConnection also but the result was the same.





QObject::connect(m_tcpsocket,SIGNAL(readyRead()),t his,SLOT(readmsg()),Qt::DirectConnection);




void QClass1::readmsg()
{
m_count++;
printf("\nCOUNT: %d",m_count);
S_Msg m_header;// this is a structure
void *ptr=&m_header;
m_tcpsocket->read((char *)ptr,MSG_SIZE);
printf("\n\nRecieved ID ");
printf("%x",m_header.id);

switch(m_header.id)
{
case 1:
{
S_LOT plt; //object for struct S_LOT
void *vptr_msg=&plt.th;
m_tcpsocket->read((char *)vptr_msg,LOT_SIZE-MSG_SIZE);
emit Signal1(plt);
break;
}
.
.
.
.
default:
//
}
}

Count output with Qt Sockets for 1000msgs sent from the server was 978
Count output with C Sockets for 1000msgs sent from the server was 1000


--
pls help

aamer4yu
3rd April 2008, 14:36
What was the number of times you recorded the comparison ??
Are u getting loss with Qt Socket all the time ??? or could it be prob of the network ??

Also whats the code with C Socket ??

csvivek
3rd April 2008, 17:09
send(sockfd,&message,sizeof(message),0);
for(;;)
{
recv(sockfd, &array, 8, 0);
if(array[3] == 0x3005)
{
//printf("PLOT from server=%4x\n", array[3]);
printf("Message %d.\n",++count);
recv(sockfd, &array, 24, 0);
}
else if(array[3] == 0x3004)
{
//printf("CAP from server=%4x\n", array[3]);
recv(sockfd, &array, 2, 0);
printf("Message %d.\n",++count);
}
}


i have tried that for atleast ten different sets.
the result is the same

fanat9
3rd April 2008, 19:16
Did you check total size of received data ? Because some "tcp messages" may bound together, but not lost.

csvivek
3rd April 2008, 19:45
Did you check total size of received data ? Because some "tcp messages" may bound together, but not lost.


what should i do to avoid that....!

wysota
3rd April 2008, 19:58
The fact that readyRead() was emitted less than 1000 times doesn't mean there are less than 1000 messages in the buffer. Instead of reading one message at a time, read as many messages at once as there are waiting in the buffer.


while(sock->bytesAvailable()>=8){
QByteArray dat = sock->read(8);
doSomething(dat);
}