Results 1 to 2 of 2

Thread: QSocketDevice: win32/x11 differences

  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QSocketDevice: win32/x11 differences

    Hello!
    I've stumbled upon udp broadcast code which works on win32 and didn't work in x11.

    Packet sender defined this way:
    Qt Code:
    1. QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
    2. #ifdef QTS_WIN32
    3. #elif QTS_LINUX
    4. int one = 1;
    5. setsockopt(udp->socket(), SOL_SOCKET, SO_BROADCAST, &one, sizeof(one));
    6. #endif
    To copy to clipboard, switch view to plain text mode 
    and it broadcasts packets this way:
    Qt Code:
    1. udp->writeBlock(some-data, some-data.length(), broadcast-address, port);
    To copy to clipboard, switch view to plain text mode 
    Packet receiver defined this way:
    Qt Code:
    1. QSocketDevice * udp = new QSocketDevice(QSocketDevice::Datagram);
    2. if(!udp->bind(some-address, port))
    3. {..}
    4. QSocketNotifier * udpn = new QSocketNotifier(udp->socket(), QSocketNotifier::Read);
    5. connect( udpn, SIGNAL( activated(int) ), this, SLOT( receiveSomething() ) );
    To copy to clipboard, switch view to plain text mode 
    When packet received, receiveSomething() fires and receiver mines data this way:
    Qt Code:
    1. QString some-data = QString(udp->readAll());
    To copy to clipboard, switch view to plain text mode 

    Packet sender works on all platforms, but receiver only on win32. Does QSocketDevice on x11 need special initialization?

  2. #2
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QSocketDevice: win32/x11 differences

    Problem solved. Adding udp->setBlocking( FALSE ) and binding receiver socket to empty QHostAddress() will do the trick.

Similar Threads

  1. QSocketDevice and udp
    By a550ee in forum Qt Programming
    Replies: 4
    Last Post: 4th October 2006, 17:27

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.