QUdpSocket difference between Windows and Linux



  • 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.



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



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



  • 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.



  • 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!



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



  • 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.



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



  • 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.



  • 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.



  • 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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.