Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Bind QWebSocket & QNetworkAccessManager to specific local Interface/IP?

    General and Desktop
    3
    8
    390
    Loading More Posts
    • 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
      Taytoo last edited by Taytoo

      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 Reply Quote 0
      • T
        Taytoo last edited by

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

        1 Reply Last reply Reply Quote 0
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

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

          Qt has to stay free or it will die.

          T 1 Reply Last reply Reply Quote 1
          • T
            Taytoo @Christian Ehrlicher last edited by

            @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 Reply Quote 0
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion last edited by

              This is currently not supported with QWebSocket

              Qt has to stay free or it will die.

              T 1 Reply Last reply Reply Quote 0
              • T
                Taytoo @Christian Ehrlicher last edited by 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_1980 1 Reply Last reply Reply Quote 1
                • aha_1980
                  aha_1980 Lifetime Qt Champion @Taytoo last edited by

                  @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 Reply Quote 0
                  • Christian Ehrlicher
                    Christian Ehrlicher Lifetime Qt Champion last edited by

                    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 has to stay free or it will die.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post