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. What does the method Connect do in websockets programming?
Forum Updated to NodeBB v4.3 + New Features

What does the method Connect do in websockets programming?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 2.7k 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.
  • Mohankumar_SM Offline
    Mohankumar_SM Offline
    Mohankumar_S
    wrote on last edited by
    #1

    I am facing difficulty in understanding the following code snippet
    connect(&m_webSocket, &QWebSocket::connected, this, &qtWebSocketClient::onConnected);

    Can somebody explain what is happening here?

    I am trying to control the connect,send,rcv aspects of the client - server application externally.

    K 1 Reply Last reply
    0
    • Mohankumar_SM Mohankumar_S

      I am facing difficulty in understanding the following code snippet
      connect(&m_webSocket, &QWebSocket::connected, this, &qtWebSocketClient::onConnected);

      Can somebody explain what is happening here?

      I am trying to control the connect,send,rcv aspects of the client - server application externally.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Mohankumar_S

      You should have a look to signal and slots
      The connect routine is connecting the signal QWebSocket::connected to the slot qtWebSocketClient::onConnected.

      The naming becomes a bit fusing when a signal is connected to something which reports basically the success of a completely unrelated connection (e.g. within the internet).

      Vote the answer(s) that helped you to solve your issue(s)

      Mohankumar_SM 1 Reply Last reply
      0
      • L Offline
        L Offline
        Lineaxe
        wrote on last edited by
        #3

        Also I believe you do have an object of the m_webSocket class created , and this is set to the current class (for me a lot of the time that is the mainwindow class). So the ' &QWebSocket::connected SIGNAL comes from the m_webSocket class '
        and the ' &qtWebSocketClient::onConnected SLOT comes from this (the current class object) '.

        Mohankumar_SM 1 Reply Last reply
        0
        • K koahnig

          @Mohankumar_S

          You should have a look to signal and slots
          The connect routine is connecting the signal QWebSocket::connected to the slot qtWebSocketClient::onConnected.

          The naming becomes a bit fusing when a signal is connected to something which reports basically the success of a completely unrelated connection (e.g. within the internet).

          Mohankumar_SM Offline
          Mohankumar_SM Offline
          Mohankumar_S
          wrote on last edited by
          #4

          @koahnig Thank you

          1 Reply Last reply
          0
          • L Lineaxe

            Also I believe you do have an object of the m_webSocket class created , and this is set to the current class (for me a lot of the time that is the mainwindow class). So the ' &QWebSocket::connected SIGNAL comes from the m_webSocket class '
            and the ' &qtWebSocketClient::onConnected SLOT comes from this (the current class object) '.

            Mohankumar_SM Offline
            Mohankumar_SM Offline
            Mohankumar_S
            wrote on last edited by Mohankumar_S
            #5

            @koahnig How to serve multiple client requests through a single server?

            K 1 Reply Last reply
            0
            • Mohankumar_SM Mohankumar_S

              @koahnig How to serve multiple client requests through a single server?

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @Mohankumar_S

              It may depend on the server implementation. Especially you need to check the web socket protocol. I have no experience there.

              In general you can send a couple of requests subsequently and wait for the corresponding replies. If the server does not maintain a stack for requests, you have to wait for each reply and send the next request. However, this is dependent on the server implementation.

              Have a look to the websocket examples. There might be one already close to what you try to do.

              Vote the answer(s) that helped you to solve your issue(s)

              Mohankumar_SM 2 Replies Last reply
              0
              • K koahnig

                @Mohankumar_S

                It may depend on the server implementation. Especially you need to check the web socket protocol. I have no experience there.

                In general you can send a couple of requests subsequently and wait for the corresponding replies. If the server does not maintain a stack for requests, you have to wait for each reply and send the next request. However, this is dependent on the server implementation.

                Have a look to the websocket examples. There might be one already close to what you try to do.

                Mohankumar_SM Offline
                Mohankumar_SM Offline
                Mohankumar_S
                wrote on last edited by
                #7

                @koahnig Thank you

                1 Reply Last reply
                0
                • K koahnig

                  @Mohankumar_S

                  It may depend on the server implementation. Especially you need to check the web socket protocol. I have no experience there.

                  In general you can send a couple of requests subsequently and wait for the corresponding replies. If the server does not maintain a stack for requests, you have to wait for each reply and send the next request. However, this is dependent on the server implementation.

                  Have a look to the websocket examples. There might be one already close to what you try to do.

                  Mohankumar_SM Offline
                  Mohankumar_SM Offline
                  Mohankumar_S
                  wrote on last edited by
                  #8

                  @koahnig I am getting the following linking error
                  /home/mohan/QtWebSocketServer/qtwebsocketserver.cpp:-1: error: undefined reference to QHostAddress::QHostAddress(QHostAddress::SpecialAddress)' /home/mohan/QtWebSocketServer/qtwebsocketserver.cpp:-1: error: undefined reference to QWebSocketServer::listen(QHostAddress const&, unsigned short)'
                  /home/mohan/QtWebSocketServer/qtwebsocketserver.cpp:-1: error: undefined reference to `QWebSocketServer::newConnection()'

                  These are my include files
                  #include "qtwebsocketserver.h"
                  #include "QtWebSockets/qwebsocketserver.h"
                  #include "QtWebSockets/qwebsocket.h"
                  #include <QtCore/QDebug>
                  QTime t;
                  QT_USE_NAMESPACE

                  This is my project file
                  QT += core
                  QT -= gui

                  CONFIG += c++11

                  TARGET = QtWebSocketServer
                  CONFIG += console
                  CONFIG -= app_bundle

                  TEMPLATE = app

                  SOURCES += main.cpp
                  qtwebsocketserver.cpp
                  iwebsocketserver.cpp
                  cwebsocketserver.cpp

                  SUBDIRS +=
                  echoclient.pro

                  DISTFILES +=
                  echoclient.pro.user
                  echoclient.html

                  HEADERS +=
                  qtwebsocketserver.h
                  iwebsocketserver.h
                  cwebsocketserver.h

                  1 Reply Last reply
                  0
                  • jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    As the documentation says you need this line in your pro file in order to use network functionality:

                    QT += network
                    

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

                    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