Results 1 to 4 of 4

Thread: Specify source port on QUdpSocket packet

  1. #1
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Specify source port on QUdpSocket packet

    Dear QT developers

    I am a kind of newbie for QT. Since sometime I developed a code/ui that communicates with some I/O devices through a UDP protocol. So I am able to communicate but the problem is that the UDP packet should be sent through a specific port because the IO device is checking the source port and the source address of the coming packet I guess through the header.

    I tried all the solutions around (binding first) but whatever I tried it didn't worked as I see with wireshark. Any help is much appreciated because I need it urgently.

    I attach a piece of code that I am using to send.

    Qt Code:
    1. void MainWindow::Sender(QByteArray blockOfData, quint16 port)
    2. {
    3. QString address = ui->baseAddressTF->text();
    4. qDebug() << "Send + Receive";
    5. socket = new QUdpSocket( this );
    6. socket->bind(QHostAddress("127.0.0.1"), 6007);
    7. socket->writeDatagram(blockOfData,QHostAddress(address), port);
    8. qDebug() << socket->errorString();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Many Many thanks in advance

    And to be more specific I want to send a packet to ip:10.0.0.2, port 6263 but through port 6007 and now I can't really seeing through wireshark that the source port is always a random port.

    Thanks again

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Specify source port on QUdpSocket packet

    What does bind() return?
    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.


  3. #3
    Join Date
    Mar 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Specify source port on QUdpSocket packet

    Guys I think I found the problem . On mac os x port 6007 is used by x11 so always the bind is giving false. I tried else and it's finally working.

    "wysota" thanks for the hint

  4. #4
    Join Date
    Oct 2011
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Specify source port on QUdpSocket packet

    Hello,
    What you have to do is modify the line:
    socket-> bind (QHostAddress ("IP_NETWORK_CARD"), 6007);
    IP_NETWORK_CARD and replace the IP address you have configured the NIC that is connected to the network.
    example:
    socket-> bind (QHostAddress ("192.168.1.101"), 6007);

    sorry my English is not very good.

Similar Threads

  1. MAC address of UDP packet's sender
    By mastupristi in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2011, 14:12
  2. QUdpSocket connectToHost and bind an the same port
    By aLiEnHeAd in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2010, 08:48
  3. QUdpSocket -- Rebinding with Different Port Numbers
    By swamyonline in forum Qt Programming
    Replies: 0
    Last Post: 22nd January 2009, 14:39
  4. how to send ICMP packet
    By eleanor in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 15:23
  5. QtNetwork send ICMP Packet
    By SlowTree in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 21:13

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.