PDA

View Full Version : QtcpServer not reading accurately from all client connections.



quickNitin
5th July 2006, 13:59
This is in refrence to my previous thread.
http://www.qtcentre.org/forum/f-newbie-4/t-also-i-need-more-guidance-on-issue-of-differentiating-data-read-from-different-socket-2861.html

Following code shows server activating a new client connection


void tcpCock::activatingNewConnection()
{
tcpSocket=tcpServer->nextPendingConnection();
connect( tcpSocket, SIGNAL(disconnected()),tcpSocket, SLOT(deleteLater()));
connect( tcpSocket,SIGNAL(readyRead()),this,SLOT(updatePixm ap()));
//provide a connect for linking socket exiting status to one of slo which disconnects drawShape() from refresh signal.
connect( tcpSocket,SIGNAL(disconnected()),this,SLOT(socketD isconnected()));
//pIntQlist= new QList<int> ;
hash.insert(tcpSocket->socketDescriptor(),new QList<int>);
}


following slot will be called when readyRead() signal is emitted by socket


void tcpCock::updatePixmap()
{

QTcpSocket *tempSock=dynamic_cast<QTcpSocket *>(sender());
if(tempSock)
{
cout<<"\n sock desc:"<<tempSock->socketDescriptor()<<"\t";
QHash<int, QList<int>* >::const_iterator itr=hash.find(tempSock->socketDescriptor());

QString st;
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_0);
if( tempSock->bytesAvailable() <= 0 )// changed from tcpSocket since tcpsocket will look for newely activeted connection only
{
//cout<<"\nNothing Available for reading";
return;
}
in >>st;
int i=0;
QChar *data = st.data();
while (*data!=' ')
{
++data;
i++;
}
QString s1=st.left(i);
x=s1.toInt();
QString s2=st.mid(i+1);
y=s2.toInt();
itr.value()->append(x);
itr.value()->append(y);
cout<<x<<" "<<y<<" ";
//move(x,y);
QgsRect r=mQGisApp->getMapCanvas()->fullExtent();
setRect(r);
show();
updateCanvas();
}
}


following code will be called as in continuition in control flow of updateCanvas() , last statement above.

problem is whenever a new socket is activated , it is not able to read data sent by client. It always read 0 0 while client donot sent it.
here is piece of output i received.



Server is listening on Port 35000
sock desc:16 0 0
0 0
sock desc:16 1 1
1 1 0 0
sock desc:16 2 2
2 2 1 1 0 0
sock desc:16 3 3
3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0
0 0 0 0 0 0 0 0 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
sock desc:16 0 0
5 5 4 4 3 3 2 2 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0

i had repeated it with multiple clients.
I couldn't figure out where exact pbm is.

regards
quick

quickNitin
5th July 2006, 14:12
i did a silly mistake,
in slot updatePixmap() , i intialized stream to open a different socket as in line 11 of updatePixmap() place of


QDataStream in(tcpSocket);


this should have been



QDataStream in(tempSock);


cya
quick