Results 1 to 2 of 2

Thread: connectToHost() to receive broadcast udp datagram

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    75
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question connectToHost() to receive broadcast udp datagram

    Can I use QAbstractSocket::connectToHost() to receive broadcast udp datagrams?

    If I try the unmodified broadcastsender/receiver all works and netstat is:
    Qt Code:
    1. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    2. udp6 0 0 :::52337 :::* 12185/./broadcastse
    3. udp6 0 0 :::45454 :::* 12172/broadcastrece
    To copy to clipboard, switch view to plain text mode 

    I modified broadcastreceiver as follow:
    Qt Code:
    1. //! [0]
    2. udpSocket = new QUdpSocket(this);
    3. udpSocket->bind(45454, QUdpSocket::ShareAddress);
    4. udpSocket->connectToHost(QHostAddress(QHostAddress::Any),0); // <- added line
    5. //! [0]
    To copy to clipboard, switch view to plain text mode 

    Now it does not receive broadcast datagrams, but it receive correctly unicast datagrams.

    the netstat command report is:
    Qt Code:
    1. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    2. udp6 0 0 ::1:45454 ::1:* ESTABLISHED 11488/broadcastrece
    To copy to clipboard, switch view to plain text mode 

    I wonder why it seems different local address, and where am I wrong.

    here is attached the examples
    qt5-examples.tar.gz

    best regards
    Max
    Last edited by mastupristi; 15th March 2017 at 09:10.

Similar Threads

  1. Replies: 1
    Last Post: 11th March 2016, 02:16
  2. QUdpsocket send and receive broadcast in linux
    By danics in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2015, 11:26
  3. Reading last datagram in UDP network
    By euch in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2010, 23:21
  4. Reading TCP datagram header by Qt
    By Kill3rReaper in forum Qt Programming
    Replies: 11
    Last Post: 8th June 2010, 12:49
  5. UDP datagram receive
    By mdannenb in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2008, 03:30

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.