Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: Ntp client does not work! urgent!

  1. #21
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4 Qt Jambi
    Platforms
    Windows

    Default Re: Ntp client does not work! urgent!

    for example i got print
    1
    18446744072894420334
    18446744071623573120
    fr 9. apr 23:06:54 2010
    3
    18446744073709551521
    18446744071623573120
    to 7. feb 07:26:41 2036

    one correct, one wrong, just in 2 seconds after i clicked connect time server button. here is the wrong time i got(or calculated after i got the udp packet)

    text Code:
    1. No. Time Source Destination Protocol Info
    2. 1725 860.103066 207.46.232.182 192.168.1.104 NTP NTP server
    3.  
    4. Frame 1725 (90 bytes on wire, 90 bytes captured)
    5. Ethernet II, Src: Arcadyan_98:a7:bc (00:1a:2a:98:a7:bc), Dst: CompalCo_66:ef:cb (00:16:d4:66:ef:cb)
    6. Internet Protocol, Src: 207.46.232.182 (207.46.232.182), Dst: 192.168.1.104 (192.168.1.104)
    7. User Datagram Protocol, Src Port: ntp (123), Dst Port: 19277 (19277)
    8. Network Time Protocol
    9. Flags: 0x1c
    10. 00.. .... = Leap Indicator: no warning (0)
    11. ..01 1... = Version number: NTP Version 3 (3)
    12. .... .100 = Mode: server (4)
    13. Peer Clock Stratum: secondary reference (3)
    14. Peer Polling Interval: invalid (0)
    15. Peer Clock Precision: 0,015625 sec
    16. Root Delay: 0,0716 sec
    17. Root Dispersion: 0,0804 sec
    18. Reference Clock ID: 69.36.241.112
    19. Reference Clock Update Time: Apr 9, 2010 21:07:27,5338 UTC
    20. Originate Time Stamp: NULL
    21. Receive Time Stamp: Apr 9, 2010 21:11:45,3768 UTC
    22. Transmit Time Stamp: Apr 9, 2010 21:11:45,3768 UTC
    23.  
    24. 0000 00 16 d4 66 ef cb 00 1a 2a 98 a7 bc 08 00 45 00 ...f....*.....E.
    25. 0010 00 4c c3 71 00 00 76 11 07 3a cf 2e e8 b6 c0 a8 .L.q..v..:......
    26. 0020 01 68 00 7b 4b 4d 00 38 13 4f 1c 03 00 fa 00 00 .h.{KM.8.O......
    27. 0030 12 56 00 00 14 92 45 24 f1 70 cf 6a 15 8f 88 a4 .V....E$.p.j....
    28. 0040 aa 6e 00 00 00 00 00 00 00 00 cf 6a 16 91 60 73 .n.........j..`s
    29. 0050 83 85 cf 6a 16 91 60 73 83 85 ...j..`s..
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 10th April 2010 at 08:30.

  2. #22
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Ntp client does not work! urgent!

    Yes, that's because your readPendingDatagrams method is incorrect. You should read into a buffer and then take the last 8 bytes of that buffer. Currently you are just overwriting the same buffer until you run out of bytes to read, so the buffer can be invalid unless it is segmented right by the tcp protocol. So it will work sometimes and not at all at others.

  3. #23
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4 Qt Jambi
    Platforms
    Windows

    Default Re: Ntp client does not work! urgent!

    I see, but how to code that, any idea? could not code more then that.. i can not still get the correct time but sometimes..

    Qt Code:
    1. while (udpSocket->hasPendingDatagrams()) {
    2. QByteArray byteArray;
    3. byteArray = udpSocket->read(48);
    4. ui->textEdit->append(QString::number(byteArray.size()));
    5.  
    6. QByteArray lastbyteArray(byteArray.right(8));
    7.  
    8. quint64 seconds = 0;
    9. for (int i=0; i<=3; ++i)
    10. {
    11. seconds = (seconds << 8) | lastbyteArray[i];
    12. }
    13.  
    14. ui->textEdit->append(QString::number(seconds, 10));
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 12th April 2010 at 08:02.

  4. #24
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Ntp client does not work! urgent!

    Each time you call udpSocket->read you need to append onto the end of your buffer. I don't think I need to describe how to do that

    Secondly, there's a chance that readyRead occurs more than once, as you may not receive all the data in a single call, so your method needs to know how much data to expect, and only parse the data when it has received a full & valid packet.

Similar Threads

  1. An Ftp Client to work with web browser
    By thewooferbbk in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2009, 09:04
  2. Urgent! help
    By Sheng in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd October 2008, 21:03
  3. [URGENT] Weird compile error [URGENT]
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 24th May 2008, 23:54
  4. Client/Server doesn't work
    By mattia in forum Newbie
    Replies: 2
    Last Post: 1st November 2007, 13:31
  5. urgent issue qt4.2
    By pratik in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2007, 16:35

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.