Results 1 to 7 of 7

Thread: Working with QUdpSocket

  1. #1
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Working with QUdpSocket

    Hi,

    I have a udpserver that is waiting for a data from a client to be connected and this server is written in C. Now i have a client who can send and receive data to this server. This client is coded with QT. I am able to send data to this server thru the writeDatagram() cal. but to recieve the data. I have used the readyRead() signal. but the slot connected is not at all getting called.

    I have not binded the object of QUdpSocket to the corresponding port or IP at the client side.
    I thought this would be the problem but when i try to bind the object. Bind is getting failed. when both the client and server are running in the same pc. i have also tried with different pc's where the bind is a success and the client server are working fine.

    Please tell me a way where i can make the binding success when both the client and server are running the same PC.
    I tried using the following code but still the problem exists with same PC.
    Qt Code:
    1. if(m_udpsocket->bind(port,QUdpSocket::ReuseAddressHint|QUdpSocket::ShareAddress))
    2. qDebug("Bind Success");
    3. else
    4. qDebug("Bind Fail");
    To copy to clipboard, switch view to plain text mode 

    kindly help me..
    Thanks in advance.
    Last edited by csvivek; 16th October 2008 at 06:49.

  2. #2
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Working with QUdpSocket

    first, leave the BindFlags away. I dont know if they arent causing the error.
    Qt Code:
    1. if(m_udpsocket->bind(port))
    2. qDebug("Bind Success");
    3. else
    4. qDebug("Bind Fail");
    To copy to clipboard, switch view to plain text mode 
    and second you should compile your app with CONFIG += console to see if theres an error with your connect method. your method should look like that:
    Qt Code:
    1. connect(udpsocket, SIGNAL(readyRead()),
    2. this, SLOT(readDatagram()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Working with QUdpSocket

    No i am not getting that kind of errors with the connect statement.
    CONFIG += console is added.

    The slot is called when both the server and client runs in different pc's. but since the bind is failed the udpsocket is in an unconnected state and hence the slot is not getting called.

    when they are run in different pc's the socket is in boundstate.

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 162 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Working with QUdpSocket


  5. #5
    Join Date
    Mar 2008
    Posts
    68
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: Working with QUdpSocket

    The Error string was QAbstractSocket::AddressInUseError.
    But the problem is solved in the server side i tried to use

    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))

    it worked. Thanks everybody for the responses and time.

  6. #6
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with QUdpSocket

    I had this happen when I had one socket sending one way and another socket sending another. A lot of copy/pasting was going on and I forgot to update one of the methods to use the commandSocket instead of the dataSocket.

    Hope that helps somebody.

  7. #7
    Join Date
    Aug 2009
    Posts
    140
    Thanks
    22
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with QUdpSocket

    Hey Caudel,

    Thanks for the errorString() tip--I didn't know about that, it's helped me get closer to a solution to my problem.

    Matt

Similar Threads

  1. Strange problems with QUdpSocket
    By montylee in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2008, 07:51
  2. QDevelop and CTags -> Not working
    By philwinder in forum Qt-based Software
    Replies: 13
    Last Post: 9th May 2008, 21:40
  3. QUdpSocket binding
    By db in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2008, 11:24
  4. Don't want QTextBrowser to look in working directory
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2007, 23:14
  5. GUI thread and Working thread comunication
    By FasTTo in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 15:31

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.