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. Bind QWebSocket & QNetworkAccessManager to specific local Interface/IP?
Forum Updated to NodeBB v4.3 + New Features

Bind QWebSocket & QNetworkAccessManager to specific local Interface/IP?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.1k 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.
  • T Offline
    T Offline
    Taytoo
    wrote on last edited by Taytoo
    #1

    Is there any way to bind QWebsocket & QNetworkAccessManager to a specific local IP?

    For QWebSocket, the only option I see is an undocumented constructor for QWebSocket which takes pQTcpSocket.

    QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version, QObject *pParent);
    

    One could theoretically create a QTcpSocket, bind it to specific IP and then pass it to websocket constructor. Would that work? Any possible issues with this?

    Couldn't find any possible way of doing the same for QNetworkAccessManager. Any ideas?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Taytoo
      wrote on last edited by
      #2

      Update: Tried passing QTcpSocket to QWebSocket constructor but compiler is giving "cannot access private member" error.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        What's wrong with QWebSocketServer::listen()?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        T 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          What's wrong with QWebSocketServer::listen()?

          T Offline
          T Offline
          Taytoo
          wrote on last edited by
          #4

          @christian-ehrlicher Its a client websocket. I want to bind client socket to a specific local interface/IP e.g. if a computer has two network cards, wifi and ethernet, and user wants software(websocket) to use ethernet interface for all communications.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            This is currently not supported with QWebSocket

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            T 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              This is currently not supported with QWebSocket

              T Offline
              T Offline
              Taytoo
              wrote on last edited by Taytoo
              #6

              @christian-ehrlicher I'm building static Qt myself. If I just add a bind method to QWebSocket and forward that call to internal pTcpSocket, would that be ok?

              Can I submit this change for inclusion into Qt code?

              aha_1980A 1 Reply Last reply
              1
              • T Taytoo

                @christian-ehrlicher I'm building static Qt myself. If I just add a bind method to QWebSocket and forward that call to internal pTcpSocket, would that be ok?

                Can I submit this change for inclusion into Qt code?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @taytoo said in Bind QWebSocket & QNetworkAccessManager to specific local Interface/IP?:

                @christian-ehrlicher I'm building static Qt myself. If I just add a bind method to QWebSocket and forward that call to internal pTcpSocket, would that be ok?

                Can I submit this change for inclusion into Qt code?

                I'm not the maintainter of QWebSocket, but I think the answer to both questions is yes.

                Have a look at https://wiki.qt.io/Qt_Contribution_Guidelines to get started with your contribution.

                Regards

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I would add something like QWebSocket::setBindAddress(const QHostAddress &address, quint16 port = 0, QAbstractSocket::BindMode mode = DefaultForPlatform) which could then be used in QWebSocketPrivate::open()

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1

                  • Login

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