Results 1 to 20 of 24

Thread: Ntp client does not work! urgent!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4 Qt Jambi
    Platforms
    Windows

    Question Ntp client does not work! urgent!

    Hi, I am trying to write a ntp client which is going to connect to a time server and get the time..could'nt find qt example although it is possiple to find many c, vc++ or c# clients.. my code does connect but does not get any datagrams, have you any idea? here is my code, i need first to retrieve the time, i did not code rest of it yet.

    Qt Code:
    1. void AtomicClock::on_TimeUpdate_clicked()
    2. {
    3. QHostInfo info = QHostInfo::fromName("0.pool.ntp.org");
    4. QString ipAddress = info.addresses().first().toString();
    5. ui->ipAddress->setText(ipAddress);
    6. udpSocket = new QUdpSocket(this);
    7. udpSocket->connectToHost("0.pool.ntp.org", 123);
    8.  
    9. connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
    10. connect(udpSocket, SIGNAL(connected()), this, SLOT(connectSuccsess()));
    11. }
    12. void AtomicClock::readPendingDatagrams()
    13. {
    14. ui->statusLabel->setText("Reading...");
    15.  
    16. while(udpSocket->hasPendingDatagrams())
    17. {
    18. QByteArray buffer(udpSocket->pendingDatagramSize(), 0);
    19. udpSocket->readDatagram(buffer.data(), buffer.size());
    20. QDataStream stream(buffer);
    21. stream.setVersion(QDataStream::Qt_4_6);
    22. QString newTime;
    23. stream >> newTime;
    24. ui->lineEdit->setText(newTime);
    25. }
    26. }
    27. void AtomicClock::connectSuccsess()
    28. {
    29. ui->time->setText("Connected");
    30. QByteArray timeRequest(48,'0');
    31. QDataStream out(&timeRequest, QIODevice::WriteOnly);
    32. out.setVersion(QDataStream::Qt_4_6);
    33.  
    34. udpSocket->writeDatagram(timeRequest, QHostAddress("0.pool.ntp.org"), 123);
    35. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 31st March 2010 at 23:25.

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
  •  
Qt is a trademark of The Qt Company.