Results 1 to 9 of 9

Thread: Problem with a UDP connection between two programs

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with a UDP connection between two programs

    a) You should separate the hardware dependent code from the network/server layer.
    That way you can test the server part independently from the hardware part.

    b) Have you tried the code at QUdpSocket? Does your "read-slot" get called? Ever?

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Problem with a UDP connection between two programs

    OK, find attached files Test_A and Test_B in Test_A_B.zip
    The slot " udpRxEvent() " of the program A is never called.
    Attached Files Attached Files

  3. #3
    Join Date
    Dec 2008
    Location
    France
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Problem with a UDP connection between two programs

    Here is the C# version of B program (without hardware dependent code)
    You can verify that the program A (Qt) works perfectly with this program B (C#)
    Attached Files Attached Files

  4. #4
    Join Date
    Dec 2008
    Location
    France
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Problem with a UDP connection between two programs

    I finaly found solution all is on the run()
    Qt Code:
    1. QTextStream out( stdout );
    2.  
    3. QUdpSocket m_socket;
    4. QByteArray datagram;
    5. QHostAddress sender;
    6. quint16 senderPort;
    7. QString in_qstr;
    8. QString resp;
    9.  
    10. if (m_socket.bind(QHostAddress::Any, 55667) == -1) {
    11. qDebug("Could not bind udp command_server socket...");
    12. m_thread_go = false;
    13. }
    14. else
    15. m_thread_go = true;
    16.  
    17. while (m_thread_go) {
    18.  
    19. if (m_socket.waitForReadyRead(100)) {
    20. if (m_socket.hasPendingDatagrams()) {
    21. datagram.resize(m_socket.pendingDatagramSize());
    22. m_socket.readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    23. in_qstr = datagram.data();
    24.  
    25. resp = ProcessCommand(in_qstr.toLower());
    26.  
    27. datagram.clear();
    28. datagram.append(resp);
    29.  
    30. if (m_socket.writeDatagram(datagram, sender, senderPort) == -1) {
    31. qDebug("dropped at write");
    32. m_socket.close();
    33. return;
    34. }
    35. if (resp == "_exit_") {
    36. m_socket.close();
    37. m_thread_go = false;
    38. emit exitCommand();
    39. }
    40. m_socket.flush();
    41. }
    42. }
    43. }
    44. m_socket.close();
    45. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. DB Connection Problem
    By ktmdwn in forum Qt Programming
    Replies: 13
    Last Post: 4th August 2010, 15:12
  2. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 08:42
  3. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  4. Problem about timer in multithread programs
    By vql in forum General Programming
    Replies: 4
    Last Post: 17th October 2007, 15:00
  5. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52

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.