Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUdpSocket difference between Windows and Linux

QUdpSocket difference between Windows and Linux

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 9.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    So I have an application running flawlessly in linux (developed and tested in ubuntu), now I am trying to get it to work on windows. I copied all the files over to my windows drive, and try to run it in Qt in windows.

    The way the software works is a broadcast gets sent out, and I get a message back. When I get a message back, I create a new socket that has a direct connection (udp) to the client and I then communicate with that specific client.

    This code works fantastic on linux, all my readyread signals get called on the broadcast and the direct udpsocket connection is made correctly and I am able to talk to the client.

    I checked all my binds / return values on windows and it shows the data is being sent correctly, yet my readyread does not get triggered like it is supposed to in windows like it does in linux.

    On windows, my broadcast socket works perfect, but my readyread on my direct udpsocket is not being hit. Keep in mind, the same code is being used between both OS's.

    Anyone know if there is a difference in communication between linux and windows with socket communication? I figured I would throw this in the air to see if there was a quick fix or something since I am still quite new to Qt4.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      There shouldn't be. However is it possible that the Windows firewall interferes?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #3

        Yeah I actually just checked that. I did try disabling the firewall and still had no affect unfortunately. :(

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          You might want to try the "Broadcast Sender":http://doc.qt.nokia.com/4.8-snapshot/network-broadcastsender.html / "Broadcast Receiver":http://doc.qt.nokia.com/4.8-snapshot/network-broadcastreceiver.html examples to see if they work on your system.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on last edited by
            #5

            The broadcast is actually the socket that does in fact work. The issue is the 2nd socket not receiving data. Is there a client receiver by any chance? :P Its weird how it works great in linux, and not in windows.

            I will give the examples a try, thank you very much for you quick reply's!

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

              There is a bunch of other "network examples":http://doc.qt.nokia.com/4.8-snapshot/examples-network.html take your pick ;) .

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vezprog
                wrote on last edited by
                #7

                So I might have found my issue. When I receive my broadcast from the client, the newly created socket is created and communicates using pointers to the address and port received by the broadcast.

                aka, when I read the broadcast I do:

                @
                udpBroadcastSocket.readDatagram(broadcast, byteSize, &address, &port); // read data
                @

                Now when I check my variables, the port is the correct number that I expected, yet the address I receive is "" (blank). Is this normal for a QHostAddress to show up ""?

                After the broadcast is received, I bind to the port using

                @
                check = udpSocket.bind(43690); // bind socket
                @

                Then I send a reply packet from the new socket.

                @
                check = udpSocket.writeDatagram(initiatepacket, 8, address, port); // write
                @

                check for the udpSocket.writeDatagram comes back to 8 bytes, but I cannot see the send in wireshark...

                This is so odd.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #8

                  Just try to set the proper address to bind to or use QHostAddress::Any:
                  @
                  check = udpSocket.bind(QHostAddress::Any,43690);
                  @

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vezprog
                    wrote on last edited by
                    #9

                    technically, I have to put my own address in there, but I thought by default that if you just define the port, the current address of the computer is already implemented into the bind function.

                    The issue seems to be with the write and how I am getting the address / opening the udp port.

                    I do not think the address is valid due to wireshark not picking up my send. It picked up the broadcast receive, broadcast send but it is not picking up the udpSocket.writedatagram.

                    Weirdly enough, the writepacket at the end when I send the reply to the new socket seems to be being sent through the broadcast socket not the udp socket.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      loladiro
                      wrote on last edited by
                      #10

                      I just looked into the source and the host adress shouldn't show up as "" unless bind() isn't called/executed properly, because
                      @
                      bool QUdpSocket::bind(quint16 port)
                      {
                      return bind(QHostAddress::Any, port);
                      }
                      @
                      And QHostAddress::Any is 0.0.0.0 . My previous suggestion is therefore unnecessary.

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vezprog
                        wrote on last edited by
                        #11

                        This is exactly whats happening:

                        Send broadcast (broadcast socket)
                        Receive broadcast (broadcast socket)
                        Get host and port from broadcast message
                        Connect on new udp socket and send packet
                        (so this is where is goes wrong, for some reason when I send out the the new udp socket, its sending out the broadcast socket from what wireshark tells me.)

                        This ONLY happens in windows, linux it works fine.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          loladiro
                          wrote on last edited by
                          #12

                          I'm out of ideas now. Could you compose a minimal compilable example demonstrating the issue?

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved