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. Unable to connect to websocket server on Android QML App

Unable to connect to websocket server on Android QML App

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 5 Posters 3.4k Views 2 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.
  • P Offline
    P Offline
    PaulGrant
    wrote on last edited by
    #1

    Hi,
    I've taken the basic websocket server example from qt5.9, place it in a android project
    and tried to connect to it from a linux based websocket client, but it refuses to accept
    a connection. I see the error in the node console.
    The same app will accept connection if run as a linux desktop app?!?

    On Android i'm using APK19.

    To test if websockets can work in this way on android I've downloaded an
    app from the android store and found I can connect to it fine!

    I checked permissions on the app and found the following:
    ACCESS_NETWORK_STATE
    ACCESS_WIFI_STATE
    CHANGE_NETWORK_STATE
    CHANGE_WIFI_STATE
    INTERNET
    I've added these to the android app, but it still refuses to accept connection!

    Is there a separate permission required for QT/QML network access?
    What would cause this?

    Any help would be appreciated!
    BR
    Paul Grant

    jsulmJ 1 Reply Last reply
    0
    • P PaulGrant

      Hi,
      I've taken the basic websocket server example from qt5.9, place it in a android project
      and tried to connect to it from a linux based websocket client, but it refuses to accept
      a connection. I see the error in the node console.
      The same app will accept connection if run as a linux desktop app?!?

      On Android i'm using APK19.

      To test if websockets can work in this way on android I've downloaded an
      app from the android store and found I can connect to it fine!

      I checked permissions on the app and found the following:
      ACCESS_NETWORK_STATE
      ACCESS_WIFI_STATE
      CHANGE_NETWORK_STATE
      CHANGE_WIFI_STATE
      INTERNET
      I've added these to the android app, but it still refuses to accept connection!

      Is there a separate permission required for QT/QML network access?
      What would cause this?

      Any help would be appreciated!
      BR
      Paul Grant

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @PaulGrant said in Unable to connect to websocket server on Android QML App:

      I see the error in the node console

      What is the error?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PaulGrant
        wrote on last edited by
        #3

        HI, error is connection refused, which seems to imply permissions issue!

        Error: connect ECONNREFUSED 192.168.1.141:8003
        at Object.exports._errnoException (util.js:870:11)
        at exports._exceptionWithHostPort (util.js:893:20)
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

        Additionally if I creat a websocket client in same QML it can communicate
        with the server, even when I change the IP of the server from localhost which is
        default to actual IP of android device. This again seems to imply a permissions issue!?!

        But I dont know of any other relavent Android permissions

        BR, Paul

        jsulmJ raven-worxR 2 Replies Last reply
        0
        • P PaulGrant

          HI, error is connection refused, which seems to imply permissions issue!

          Error: connect ECONNREFUSED 192.168.1.141:8003
          at Object.exports._errnoException (util.js:870:11)
          at exports._exceptionWithHostPort (util.js:893:20)
          at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

          Additionally if I creat a websocket client in same QML it can communicate
          with the server, even when I change the IP of the server from localhost which is
          default to actual IP of android device. This again seems to imply a permissions issue!?!

          But I dont know of any other relavent Android permissions

          BR, Paul

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @PaulGrant I'm not an Android expert, but I can imagine that Android does not allow connections from outside of the device for security reasons.
          Why would you want to have a server on your phone?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Im no expert either but fooling around with my old one and trying stuff i had to root it to connect to it
            https://www.digitaltrends.com/mobile/how-to-make-an-android-server/

            1 Reply Last reply
            0
            • P PaulGrant

              HI, error is connection refused, which seems to imply permissions issue!

              Error: connect ECONNREFUSED 192.168.1.141:8003
              at Object.exports._errnoException (util.js:870:11)
              at exports._exceptionWithHostPort (util.js:893:20)
              at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

              Additionally if I creat a websocket client in same QML it can communicate
              with the server, even when I change the IP of the server from localhost which is
              default to actual IP of android device. This again seems to imply a permissions issue!?!

              But I dont know of any other relavent Android permissions

              BR, Paul

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @PaulGrant
              i am also not an android expert :P
              But following points come to my mind:

              1. are you sure your web-socket server listens on port 8003?
              2. do you let your websocket server listen on QHostAddress::Any network address/interface?
              3. maybe you can try to launch the server only as soon as a network/WiFi connection is available?

              the most important permission is the INTERNET permission, since this lets you open network sockets.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aneh
                wrote on last edited by
                #7

                You can use OKHTTP3 WebSocket which is really very easy to configure in android you can try this post: https://trinitytuts.com/connect-to-websocket-on-android-using-okhttp/

                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