Results 1 to 8 of 8

Thread: udpsocket cannot bind,

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default udpsocket cannot bind,

    I am running a udpsocket client program which writes to and reads from server. when I run it, bind() returns false. Although I can still send data but I am wondering why sockets cannot bind and trigger readState slot.

    As I checked a udp client does not bind, so I only set the port when initialized it. later I write like this:

    Qt Code:
    1. void UDP::UDPInit(int port)
    2. {
    3. socketPort = port;
    4. udpsocket = new QUdpSocket(this);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void UDP::sendCommand(QByteArray data)
    2. {
    3. if(udpsocket->writeDatagram(data.data(),QHostAddress(ip),socketPort)==-1)
    4. emit clientLogMessage(QString("UDPCLIENT : Write problem !"));
    5. else
    6. udpsocket->flush();
    7.  
    8. // QByteArray datagram;
    9. // int m = udpsocket->read(datagram.data(), 11);
    10. // qDebug() << errno;
    11. // qDebug() << m;
    12.  
    13. while (!udpsocket->hasPendingDatagrams()) {
    14. QByteArray datagram;
    15. datagram.resize(udpsocket->pendingDatagramSize());
    16. qDebug() << udpsocket->pendingDatagramSize();
    17. udpsocket->readDatagram(datagram.data(), datagram.size());
    18. emit dataReceived(datagram);
    19. }
    20. }
    21.  
    22. but the result is -1 and it does not read anything from it. WHY? how can I solve this problem?
    To copy to clipboard, switch view to plain text mode 
    Last edited by saman_artorious; 23rd October 2013 at 13:27.

Similar Threads

  1. Replies: 3
    Last Post: 4th September 2010, 22:48
  2. Broadcast string with udpsocket
    By wirasto in forum Qt Programming
    Replies: 5
    Last Post: 23rd September 2009, 11:13
  3. UdpSocket bind warning--pls have a look
    By swamyonline in forum Qt Programming
    Replies: 0
    Last Post: 28th August 2008, 11:42
  4. How to destroy a UdpSocket completely
    By ms20020048 in forum Qt Programming
    Replies: 2
    Last Post: 23rd October 2006, 19:01

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.