Results 1 to 13 of 13

Thread: UDP Communication issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question UDP Communication issue

    Hello

    I’m making an application with an UDP client/server communication.
    The client has to open the 3301 port on his router to receive the socket. (and the server has to open the 3300, but that is not importante)
    And I would like to know how I could receive the socket on the PC's client without this opening port.

    Server Side :
    -Listening
    Qt Code:
    1. m_udpSocket = new QUdpSocket;
    2. m_udpSocket->bind(QHostAddress::Any, 3300, QUdpSocket::ShareAddress);
    3. connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(get()));
    To copy to clipboard, switch view to plain text mode 

    -Sending
    Qt Code:
    1. QUdpSocket udpSocket;
    2. udpSocket.bind(3301); // I don't know if that is important
    3. udpSocket.writeDatagram(datagram, ip, 3301);
    To copy to clipboard, switch view to plain text mode 


    Client Side :
    -Listening
    Qt Code:
    1. m_serverAdress = new QHostAddress("**.**.***.**");
    2.  
    3. m_udpSocket = new QUdpSocket;
    4. m_udpSocket->bind(QHostAddress::Any, 3301, QUdpSocket::ShareAddress); /// if I put *m_serverAdress instead of QHostAddress::Any, I receive nothing even with the port openning
    5. connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(get()));
    To copy to clipboard, switch view to plain text mode 

    -Sending
    Qt Code:
    1. m_udpSocket->writeDatagram(datagram, *m_serverAdress, 3300);
    To copy to clipboard, switch view to plain text mode 


    Thanks You

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    You can't. If it was possible, using firewalls wouldn't make sense because any application could have overriden it. The only thing you could do is to use a port that the firewall passes through like the HTTP port (TCP/80) but you need to have some mechanism that will proxy the traffic or you can set up a VPN connection but one way or another this requires a manual intervention somewhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    Are you really sure ? Because I heard that it could work with some router.
    And if I analyse with Wireshark (a network protocol analyzer) some application like Skype, I see that my PC can receive UDP socket without openning port.

    Thanks you for your help

  4. #4
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    This method works with me and my co-developer :
    Client side :
    Qt Code:
    1. //Ecoute
    2. m_udpSocket = new QUdpSocket;
    3. m_udpSocket->bind(QHostAddress::Any, m_port, QUdpSocket::ShareAddress);
    4. connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(get()));
    5.  
    6. // ...
    7.  
    8. //Envoi
    9. m_udpSocket->writeDatagram(datagram, *m_adresseServeur, m_port);
    To copy to clipboard, switch view to plain text mode 


    Serveur side:
    Qt Code:
    1. //Ecoute
    2. m_udpSocket = new QUdpSocket;
    3. m_udpSocket->bind(QHostAddress::Any, m_port, QUdpSocket::ShareAddress);
    4. connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(get()));
    5.  
    6. // ...
    7.  
    8. //Envoi
    9. m_udpSocket->writeDatagram(datagram, ipCLient, m_port);
    To copy to clipboard, switch view to plain text mode 

    You have to use the same port and the same socket to receive and to send.
    Ok, problem is clear.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    Hmm? No, you don't have to use the same port, that's a false assumption
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    Ok, but I don't succeed with a lot of other method and test, with two ports. Maybe you know what I have to do in the code to succeed.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    In my opinion this is not a matter of your code but of the router that drops the transmission.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    But is it better to use two ports ?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    And this proves... what? Apart from the fact that you didn't bind the socket anywhere, of course...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    Yes sorry, I saw and I edited my post ^^

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    It's not that it's better or worse. You can do as many ports as you wish and this won't make your transmission to be accepted or dropped by the router (unless of course it is configured to do so, but this only works on a case by case basis).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Feb 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: UDP Communication issue

    Ok thanks.

    Until now I do my test on simple application. Now I do the modification on my real application (a FPS) :

    remplace
    Qt Code:
    1. m_udpSocket->writeDatagram(datagram, ipCLient, m_port);
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. QUdpSocket udpSocket;
    2. udpSocket.writeDatagram(datagram, ipCLient, m_port);
    To copy to clipboard, switch view to plain text mode 

    and when the server or the client run the line m_udpSocket->writeDatagram(datagram, ipCLient, m_port); the application stop working.
    Maybe you have an idea ? I tested to do waitForBytesWritten but it change nothing

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: UDP Communication issue

    I bet dollars against nuts that your socket object goes out of scope before any data has a chance to leave it (in the second case).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 28th October 2008, 16:29
  2. qt4.4 pc specs requirements or qt3 support issue?
    By triperzonak in forum Installation and Deployment
    Replies: 0
    Last Post: 9th August 2008, 02:40
  3. Data communication between multiple computers
    By AlbertGoodwill in forum Newbie
    Replies: 2
    Last Post: 8th October 2007, 13:44
  4. qt3 to qt4 - uic issue
    By hvengel in forum Qt Programming
    Replies: 10
    Last Post: 4th March 2007, 02:59
  5. Replies: 5
    Last Post: 22nd September 2006, 08:04

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.