Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QUdpSocket does not work on Windows Phone 8.1 ?
Qt 6.11 is out! See what's new in the release blog

QUdpSocket does not work on Windows Phone 8.1 ?

Scheduled Pinned Locked Moved Mobile and Embedded
13 Posts 6 Posters 4.8k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jea1768
    wrote on last edited by
    #1

    I cannot make QUdpSocket working on WP8.1
    The code works fine on Linux, Android & Windows Desktop but not on WP8.1 ...
    I always get "UnknownSocketError" (bind result always false).
    Tried different combinaisons of addresses, etc.

    Same problem on the emulator and on a real phone, bind does not succeed !

    Does anybody have some experience with UDP/TCP on WP8.1 - Do I need to set a permission ? Where ?
    Thanks.
    @
    MultipurposeUDPSocket::MultipurposeUDPSocket(QTextBrowser *tbLog, int portUDP, QObject *parent) : QObject(parent)
    {
    this->tbLog = tbLog;
    this->portUDP = portUDP;
    udpSocket = new QUdpSocket();
    connect(udpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
    QHostAddress address;
    address.setAddress("127.0.0.1"); //192.168.0.255");
    bool resbind = udpSocket->bind(address, portUDP, QAbstractSocket::DefaultForPlatform);
    if ( resbind == false )
    tbLog->append("CANNOT BIND");
    connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
    }
    void MultipurposeUDPSocket::slotSocketError(QAbstractSocket::SocketError err)
    {
    switch ( err )
    {
    case QAbstractSocket::ConnectionRefusedError: tbLog->append("ConnectionRefused"); break;
    case QAbstractSocket::RemoteHostClosedError: tbLog->append("RemoteHostClosedError"); break;
    case QAbstractSocket::HostNotFoundError: tbLog->append("HostNotFoundError"); break;
    case QAbstractSocket::SocketAccessError: tbLog->append("SocketAccessError"); break;
    case QAbstractSocket::SocketResourceError: tbLog->append("SocketResourceError"); break;
    case QAbstractSocket::SocketTimeoutError: tbLog->append("SocketTimeoutError"); break;
    case QAbstractSocket::DatagramTooLargeError: break; tbLog->append("DatagramTooLargeError");
    case QAbstractSocket::NetworkError: tbLog->append("NetworkError"); break;
    case QAbstractSocket::AddressInUseError: tbLog->append("AddressInUseError"); break;
    case QAbstractSocket::SocketAddressNotAvailableError: tbLog->append("SocketAddressNotAvailableError"); break;
    case QAbstractSocket::UnsupportedSocketOperationError: tbLog->append("UnsupportedSocketOperationError"); break;
    case QAbstractSocket::ProxyAuthenticationRequiredError: tbLog->append("ProxyAuthenticationRequiredError"); break;
    case QAbstractSocket::SslHandshakeFailedError: tbLog->append("SslHandshakeFailedError"); break;
    case QAbstractSocket::UnfinishedSocketOperationError: tbLog->append("UnfinishedSocketOperationError"); break;
    case QAbstractSocket::ProxyConnectionRefusedError: tbLog->append("ProxyConnectionRefusedError"); break;
    case QAbstractSocket::ProxyConnectionClosedError: tbLog->append("ProxyConnectionClosedError"); break;
    case QAbstractSocket::ProxyConnectionTimeoutError: tbLog->append("ProxyConnectionTimeoutError"); break;
    case QAbstractSocket::ProxyNotFoundError: tbLog->append("ProxyNotFoundError"); break;
    case QAbstractSocket::ProxyProtocolError: tbLog->append("ProxyProtocolError"); break;
    case QAbstractSocket::OperationError: tbLog->append("OperationError"); break;
    case QAbstractSocket::SslInternalError: tbLog->append("SslInternalError"); break;
    case QAbstractSocket::SslInvalidUserDataError: tbLog->append("SslInvalidUserDataError"); break;
    case QAbstractSocket::TemporaryError: tbLog->append("TemporaryError"); break;
    case QAbstractSocket::UnknownSocketError: tbLog->append("UnknownSocketError"); break; // -1 An unidentified error
    }
    }
    @

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You should use Code tags to help reading your example code. Just add at-sign before and after, see:

      @
      // code:
      bool function() {
      return true;
      }
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I'm about just guessing here, but.

        Have you checked you have localhost 127.0.0.1 on you Windows-machine? Sometimes it can have only ip6-address, and then that won't work. You could just use the bind-function that does not take QHostAdress as parameter. That uses QHostAddress::Any.

        Have you checked the return value for error() and errorString() from your udpSocket?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          I don't have any experience with Windows Phone 8.1 but Just a quick idea: did you check that the bearer plugins are deployed with your application ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jea1768
            wrote on last edited by
            #5

            Hello,
            The problem is that when you look into the '.../winphone_arm/plugins' folder, there is no 'bearer' subfolder (qt-opensource-windows-x86-winrt-5.x package install) ?! Whereas in '.../android-armv7/plugins' folder, the subfolder 'bearer' is there with 'libqandroidbearer.so'. (qt-opensource-windows-x86-android-5.x package install)
            So, I suppose there's no bearer.dll plugin for winphone ?
            For Android I did not include the plugin and it is working without it.
            By the way what is the best way to register this plugin in the app ?

            • Add QTPLUGIN += qandroidbearer in .pro
            • Add Q_IMPORT_PLUGIN(qandroidbearer) in main.cpp ?
              Thanks

            To answer Vivelu, errorString() returns also "Unknown error" with just udpSocket->bind();

            1 Reply Last reply
            0
            • M Offline
              M Offline
              miskol
              wrote on last edited by
              #6

              from my experience with WP and C sockets (winsock)
              sometimes it isn't routed right way
              It looks like you are connected to wifi but
              OS route all connection to GSM module :)

              I remember that symbian has similar behavior and they had some sort of api how to select proper network device

              at least WP 8.0 has this behavior

              I hope that Qt Http class use windows http stack as it is also wired but wp http stack is working right :)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jea1768
                wrote on last edited by
                #7

                Partially solved !
                I can now receive datagrams on a real device (not working in the emulator) by adding:
                @
                <Capabilities>
                <Capability Name="internetClientServer"/>
                <Capability Name="privateNetworkClientServer"/>
                </Capabilities>
                @
                after the </Applications> tag in appxManifest.xml file. (just "internetClientServer" should be enough).

                bind() to UDP port is now OK.

                BUT I can still not anything emit from the device ?!.
                @
                QHostAddress address;
                address.setAddress("127.0.0.1"); //192.168.0.255"); //192.168.0.100"); // 192.168.0.0");
                qint64 res = udpSocket->writeDatagram(datagram.data(), datagram.size(), address, portUDP);
                tbLog->append("Written "+QString::number(res));
                @
                seems to run OK as I receive back the correct number of bytes written and no error - but the datagram is not received/seen by any of my devices: linux & windows desktop neither by android phones on my local net (192.168.0.x)
                As I wrote, the code is running perfectly on Linux & Android !

                I've tried all possible of IP address combinaison (UDP broadcast is not supported on WP8.1) and I can not understand why, even, the local address 127.0.0.1 is not working !

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Are you sure that the machine where you send the UDP packets to receives them? In my case "writeDatagram" returns the correct number of bytes but the data is never received on the other machine.
                  As the UDP protocol is stateless, "writeDatagram" cannot know if the bytes where received by the other machine.

                  I think that the QUdpSocket is not working on WP 8.1.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    There seems to be a bug in the QUdpSocket implementation for WinRT/Phone. I have checked the QUdpSocket files source code without finding the bug.

                    But when I implement the UDP socket (bypassing the QUdpSocket) by myself based on this example [1] then everything works fine.

                    [1] https://code.msdn.microsoft.com/windowsapps/DatagramSocket-sample-76a7d82b/

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      I just noticed that there is already a bug report describing exactly our problem: https://bugreports.qt.io/browse/QTBUG-44051

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jea1768
                        wrote on last edited by
                        #11

                        Hello Lynic,
                        Thanks a lot for your analysis ! Maybe will be corrected in release 5.5.x
                        (?) - In the meantime, I'll try also to bypass QUdp as you suggested with the example.
                        Now trying to get the Bluetooth working which seems also buggy/incomplete on the WinRT platform, but it is an other story...

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by A Former User
                          #12

                          Hi all,

                          I found this thread while playing around with UDP sockets and searching for info. It seems that the QTBUG-44051 is now solved and indeed I can correctly send a broadcast message via UDP. However, received data does seem to be totally wrong for some reason.

                          I've the following code to search for a target device in the LAN. As the OP's code, mine works perfectly fine on all platforms (Win, Mac, Linux, iOS and Android) expect WinPhone:

                          udpSocket = new QUdpSocket(this);
                          if(udpSocket->bind(BROADCAST_PORT)) 
                          {
                              foreach (QNetworkInterface iff, ifs)
                              {
                                  if(iff.isValid() && !(iff.flags() & QNetworkInterface::IsLoopBack) &&
                                          (iff.flags() & QNetworkInterface::CanBroadcast) &&
                                          (iff.flags() & QNetworkInterface::IsRunning) && (iff.addressEntries().size() > 0))
                                  {
                                      foreach(QNetworkAddressEntry a, iff.addressEntries())
                                      {
                                          if(a.ip().protocol() == QAbstractSocket::IPv4Protocol)
                                          {
                                              udpSocket->writeDatagram(data, length, a.broadcast(), BROADCAST_PORT);
                                          }
                                      }
                                  }
                              }
                          }
                          

                          I had to comment out some of the checks - maybe because bearer management is not implemented in WinPhone. That's fine and allowed the data sending. We have also checked that the data is correctly received by the target device via debugger.

                          As for what regard data reception, my UDP socket receives both the message itself (since it is a broadcast one) and the reply from the target device. The number of received bytes is correct in both cases: I send 4 bytes and I should receive 15 bytes from the target device. HOWEVER, the received content has the WRONG value of:

                          \0x00cdcdcd    // original message sent by my code
                          

                          and

                          \0x00cdcdcdcdcdcdcdcdcdcdcdcdcdcd    // answer from the target device
                          

                          Am I doing something wrong, the missing bearer management affects the UDP broadcast behaviour or have I found a (quite strange) bug in Winphone qt network code?

                          Any help is really appreciated.
                          Thanks in advance.

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by A Former User
                            #13

                            To everyone searching for an answer: according to developers, the WinPhone implementation of the network interface lacks some functionalities. I've opened a bug report which can be followed here.

                            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