Results 1 to 8 of 8

Thread: tftp with QUdpSocket - cannot do - have to use Q3SocketDevice

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: tftp with QUdpSocket - cannot do - have to use Q3SocketDevice

    Use QUdpSocket::bind() to bind your socket to a specified port.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jul 2012
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tftp with QUdpSocket - cannot do - have to use Q3SocketDevice

    perfect!
    When I tried bind() I still had the conenctToHost(), my bad!

    Problem solved, thank's a lot!

    the correct source code, if it can help someone else:
    Qt Code:
    1. basicTester::basicTester(QObject *parent) :
    2. QObject(parent)
    3. {
    4. dAddr = QHostAddress("192.168.111.84"); //tftp server address
    5. dPort = 69;
    6. sock = new QUdpSocket(this);
    7. connect(sock, SIGNAL(readyRead()), this, SLOT(readData()));
    8. sock->bind(2152); /// \TODO need generate random client TID, and check if port available (select another if not) ; see RFC1350
    9. }
    10.  
    11. void basicTester::send() {
    12. QByteArray dgram;
    13. QString remote("myfile.txt");
    14. QString modestring ("octet");
    15. dgram.resize(( 2 + remote.length() + 1 + modestring.length() + 1 ));
    16.  
    17. //TFTP WRQ
    18. dgram[0] = 0x00;
    19. dgram[1] = 0x02;
    20. memcpy( dgram.data()+2, remote.toAscii(), remote.length() +1 );
    21. memcpy( dgram.data()+2+remote.length()+1, modestring.toAscii(), modestring.length() +1 );
    22.  
    23. qDebug() << "Writing dgram to " << dAddr << ":" << dPort;
    24. if(sock->writeDatagram(dgram, dAddr, dPort) == -1){
    25. qDebug() << "Error sending WRQ packet " << sock->errorString();
    26. }
    27. qDebug() << "sock peer : " << sock->peerAddress() << sock->peerPort();
    28. qDebug() << "sock local: " << sock->localAddress() << sock->localPort();
    29. }
    30.  
    31. void basicTester::readData() {
    32. qDebug() << "basicTester::readData";
    33. while(sock->hasPendingDatagrams()){
    34. QByteArray datagram;
    35. datagram.resize(sock->pendingDatagramSize());
    36. QHostAddress sender;
    37. quint16 senderPort;
    38. sock->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    39. qDebug() << "tftp server response : " << datagram.toHex();
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: tftp with QUdpSocket - cannot do - have to use Q3SocketDevice

    Quote Originally Posted by yvan40 View Post
    perfect!
    Qt Code:
    1. sock->bind(2152); /// \TODO need generate random client TID, and check if port available (select another if not) ; see RFC1350
    To copy to clipboard, switch view to plain text mode 
    No need to worry about available ports if you let bind() handle it for you like this:
    Qt Code:
    1. sock->bind();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Not getting readyRead from a QUdpSocket
    By evelBist in forum Newbie
    Replies: 3
    Last Post: 20th July 2010, 19:43
  2. Working with QUdpSocket
    By csvivek in forum Qt Programming
    Replies: 6
    Last Post: 30th October 2009, 01:38
  3. QUdpSocket and bytesAvailable
    By babu198649 in forum Newbie
    Replies: 0
    Last Post: 10th December 2008, 10:49
  4. UDP - QUdpSocket
    By denwelzie in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2008, 09:02
  5. QUdpSocket hasPendingDatagrams()
    By mbjerkne in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 19:14

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.