Results 1 to 2 of 2

Thread: QtcpServer not reading accurately from all client connections.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QtcpServer not reading accurately from all client connections.

    This is in refrence to my previous thread.
    http://www.qtcentre.org/forum/f-newb...cket-2861.html

    Following code shows server activating a new client connection
    Qt Code:
    1. void tcpCock::activatingNewConnection()
    2. {
    3. tcpSocket=tcpServer->nextPendingConnection();
    4. connect( tcpSocket, SIGNAL(disconnected()),tcpSocket, SLOT(deleteLater()));
    5. connect( tcpSocket,SIGNAL(readyRead()),this,SLOT(updatePixmap()));
    6. //provide a connect for linking socket exiting status to one of slo which disconnects drawShape() from refresh signal.
    7. connect( tcpSocket,SIGNAL(disconnected()),this,SLOT(socketDisconnected()));
    8. //pIntQlist= new QList<int> ;
    9. hash.insert(tcpSocket->socketDescriptor(),new QList<int>);
    10. }
    To copy to clipboard, switch view to plain text mode 

    following slot will be called when readyRead() signal is emitted by socket
    Qt Code:
    1. void tcpCock::updatePixmap()
    2. {
    3.  
    4. QTcpSocket *tempSock=dynamic_cast<QTcpSocket *>(sender());
    5. if(tempSock)
    6. {
    7. cout<<"\n sock desc:"<<tempSock->socketDescriptor()<<"\t";
    8. QHash<int, QList<int>* >::const_iterator itr=hash.find(tempSock->socketDescriptor());
    9.  
    10. QString st;
    11. QDataStream in(tcpSocket);
    12. in.setVersion(QDataStream::Qt_4_0);
    13. if( tempSock->bytesAvailable() <= 0 )// changed from tcpSocket since tcpsocket will look for newely activeted connection only
    14. {
    15. //cout<<"\nNothing Available for reading";
    16. return;
    17. }
    18. in >>st;
    19. int i=0;
    20. QChar *data = st.data();
    21. while (*data!=' ')
    22. {
    23. ++data;
    24. i++;
    25. }
    26. QString s1=st.left(i);
    27. x=s1.toInt();
    28. QString s2=st.mid(i+1);
    29. y=s2.toInt();
    30. itr.value()->append(x);
    31. itr.value()->append(y);
    32. cout<<x<<" "<<y<<" ";
    33. //move(x,y);
    34. QgsRect r=mQGisApp->getMapCanvas()->fullExtent();
    35. setRect(r);
    36. show();
    37. updateCanvas();
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Qt Code:
    1. Server is listening on Port 35000
    2. sock desc:16 0 0
    3. 0 0
    4. sock desc:16 1 1
    5. 1 1 0 0
    6. sock desc:16 2 2
    7. 2 2 1 1 0 0
    8. sock desc:16 3 3
    9. 3 3 2 2 1 1 0 0
    10. sock desc:16 4 4
    11. 4 4 3 3 2 2 1 1 0 0
    12. sock desc:16 5 5
    13. 5 5 4 4 3 3 2 2 1 1 0 0
    14. sock desc:16 6 6
    15. 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    16. sock desc:16 7 7
    17. 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    18. sock desc:16 8 8
    19. 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    20. sock desc:16 9 9
    21. 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    22. sock desc:17 0 0
    23. 0 0
    24. 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    25. sock desc:16 0 0
    26. 0 0
    27. 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    28. sock desc:17 1 1
    29. 1 1 0 0
    30. 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    31. sock desc:16 0 0
    32. 1 1 0 0
    33. 0 0 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    34. sock desc:17 2 2
    35. 2 2 1 1 0 0
    36. 0 0 0 0 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
    37. sock desc:16 0 0
    38. 2 2 1 1 0 0
    39. 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
    40. sock desc:17 3 3
    41. 3 3 2 2 1 1 0 0
    42. 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
    43. sock desc:16 0 0
    44. 3 3 2 2 1 1 0 0
    45. 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
    46. sock desc:17 4 4
    47. 4 4 3 3 2 2 1 1 0 0
    48. 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
    49. sock desc:16 0 0
    50. 4 4 3 3 2 2 1 1 0 0
    51. 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
    52. sock desc:17 5 5
    53. 5 5 4 4 3 3 2 2 1 1 0 0
    54. 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
    55. sock desc:16 0 0
    56. 5 5 4 4 3 3 2 2 1 1 0 0
    57. 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
    To copy to clipboard, switch view to plain text mode 
    i had repeated it with multiple clients.
    I couldn't figure out where exact pbm is.

    regards
    quick

  2. #2
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QtcpServer not reading accurately from all client connections.

    i did a silly mistake,
    in slot updatePixmap() , i intialized stream to open a different socket as in line 11 of updatePixmap() place of
    Qt Code:
    1. QDataStream in(tcpSocket);
    To copy to clipboard, switch view to plain text mode 

    this should have been

    Qt Code:
    1. QDataStream in(tempSock);
    To copy to clipboard, switch view to plain text mode 

    cya
    quick

Similar Threads

  1. Replies: 6
    Last Post: 8th January 2007, 10:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.