Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Extending networking/socket programming functionality of a qml project
Forum Updated to NodeBB v4.3 + New Features

Extending networking/socket programming functionality of a qml project

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
92 Posts 5 Posters 18.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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Are you thinking peer to peer connection ?
    Central server with multiple client ?
    Chat like application ?
    One device is the server and the other is the client ?

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

    Q 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Are you thinking peer to peer connection ?
      Central server with multiple client ?
      Chat like application ?
      One device is the server and the other is the client ?

      Q Offline
      Q Offline
      qcoderpro
      wrote on last edited by
      #3

      @SGaist

      Are you thinking peer to peer connection ?
      Chat like application ?
      One device is the server and the other is the client ?

      Yes.
      One to one and exchanging string messages. Very simple.

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

        From the looks of it, the Network Chat Example would be worth a read.

        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
        • Q Offline
          Q Offline
          qcoderpro
          wrote on last edited by
          #5

          Chatting the way that example provides with many chatters and a chat room is not what was needed. Furthermore it says: Launch several instances of this program on your local network and start chatting! What's needed is beyond local network.

          The projects work fine in all the following ways, when:

          1- they're both running using Desktop kit (on Windows)
          2- they're both running on the same virtual Android device (on Windows)
          3- the server is run using Desktop kit and client is running on a virtual Android device.

          But the intention is, for instance, you install one of the apps on your Android device and send the other to your friend in another city and you two can exchange messages together, each time a message from you or they. I hope it is now obvious for you all.

          If code for the projects is required I can share it here or anywhere else you find suitable.

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

            You have an architectural issue here. You will try to connect to a server which might change IP address at any time. You also need a secondary communication channel to share said address as well as port number. Secondary channel that you will have to use pretty regularly in order to be able to keep the communication going.

            Also, what about messages that cannot reach the other phone because its offline, out of network access, etc ?

            KDAB wrote a pretty interesting article about building a chat application which I recommend you to read.

            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
            2
            • Q qcoderpro

              Chatting the way that example provides with many chatters and a chat room is not what was needed. Furthermore it says: Launch several instances of this program on your local network and start chatting! What's needed is beyond local network.

              The projects work fine in all the following ways, when:

              1- they're both running using Desktop kit (on Windows)
              2- they're both running on the same virtual Android device (on Windows)
              3- the server is run using Desktop kit and client is running on a virtual Android device.

              But the intention is, for instance, you install one of the apps on your Android device and send the other to your friend in another city and you two can exchange messages together, each time a message from you or they. I hope it is now obvious for you all.

              If code for the projects is required I can share it here or anywhere else you find suitable.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #7

              @qcoderpro said in Extending networking/socket programming functionality of a qml project:

              you install one of the apps on your Android device and send the other to your friend in another city and you two can exchange messages together

              Unless you relax the security settings of one of the devices this will not work. You'll need a central server. This is not a restriction of the Qt framework, it's how all chatting applications work (the most famous messaging apps show the famous "double tick", one tick when the central server receives it, one tick when the second person receives the message).

              You can also take a look at https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application where the chat logic is separate from the UI so it's easier to just replace the UI in QML. In any case you will need a server application that lives in a machine that is set up to accept incoming connection from the internet (client machines usually can't for security reason) and 2 clients that connect to it

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              Q 1 Reply Last reply
              2
              • Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #8

                @SGaist

                You have an architectural issue here. You will try to connect to a server which might change IP address at any time.

                Does it mean that from the time the server provides us with the IP (and port) on, that IP ( and port) may change and not usable by the client? Is it because the IP is public and non-static, so it can change at any given second?

                You also need a secondary communication channel to share said address as well as port number. Secondary channel that you will have to use pretty regularly in order to be able to keep the communication going.

                Does it mean that such a channel will keep the IP (and port) static to be usable on the client side? If so, what is that channel,please?

                Also, what about messages that cannot reach the other phone because its offline, out of network access, etc ?

                For simplicity reasons, we try to keep both users online throughout our connection for testing it.

                1 Reply Last reply
                0
                • VRoninV VRonin

                  @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                  you install one of the apps on your Android device and send the other to your friend in another city and you two can exchange messages together

                  Unless you relax the security settings of one of the devices this will not work. You'll need a central server. This is not a restriction of the Qt framework, it's how all chatting applications work (the most famous messaging apps show the famous "double tick", one tick when the central server receives it, one tick when the second person receives the message).

                  You can also take a look at https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application where the chat logic is separate from the UI so it's easier to just replace the UI in QML. In any case you will need a server application that lives in a machine that is set up to accept incoming connection from the internet (client machines usually can't for security reason) and 2 clients that connect to it

                  Q Offline
                  Q Offline
                  qcoderpro
                  wrote on last edited by
                  #9

                  @VRonin

                  Unless you relax the security settings of one of the devices this will not work. You'll need a central server. This is not a restriction of the Qt framework, it's how all chatting applications work (the most famous messaging apps show the famous "double tick", one tick when the central server receives it, one tick when the second person receives the message).

                  Does it also mean that for such a simple communication (exchanging string messages) through global Internet we need a static IP/central sever? (like what SGaist believes I guess.)

                  Also, thank you both for your links to those two examples, but consider my current situation, please.
                  My two QML projects (with 3 files for each: .h, .cpp, and .qml - totally 6 files) contain nearly half the number of code lines of the two QWidget Fortune client/server projects, while the qml projects are different in two aspects:
                  1- the sender is able to send any string message to the receiver
                  2- the receiver is also able to send messages back.
                  It was a huge jump in my socket programming/networking learning journey, a great part of which was possible because of your help.
                  I took a look at the two links you sent me and they are undoubtedly very worthwhile I'm sure, but they're also very vast and huge for my current level! :(
                  I decided to step forward and learn new things step-by-step. After gaining a goal in my projects, I like to extend them only one step more each time. That way I guess I can make progress better and easier without being bewildered and confused with lots of new and complicated code.
                  I hope you understand me. :)

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

                    Here is the thing: network programming is not simple as soon as you put internet in the mix.

                    Hence, taking the time to study more complexe but detailed examples will help you faster than trying to make things work in a complexe setup. The chat is a good example: simple implementation for local networks, it requires more bricks when you start making a service that shall work across networks on different devices.

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

                    Q 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Here is the thing: network programming is not simple as soon as you put internet in the mix.

                      Hence, taking the time to study more complexe but detailed examples will help you faster than trying to make things work in a complexe setup. The chat is a good example: simple implementation for local networks, it requires more bricks when you start making a service that shall work across networks on different devices.

                      Q Offline
                      Q Offline
                      qcoderpro
                      wrote on last edited by
                      #11

                      @SGaist

                      Here is the thing: network programming is not simple as soon as you put internet in the mix.
                      Hence, taking the time to study more complexe but detailed examples will help you faster than trying to make things work in a complexe setup. The chat is a good example: simple implementation for local networks, it requires more bricks when you start making a service that shall work across networks on different devices.

                      Yeah, sure. I understand and will certainly study that chat example in near future, but for now I just like to extend my two projects so that they can work through global Internet.

                      Will you answer the questions I asked above, please? They're important for me.

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

                        Static address is not required if you have a DNS resolvable name.

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

                        Q 1 Reply Last reply
                        2
                        • VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #13

                          Your problem is not an application one (if it works over LAN it means that you programmed it correctly), it’s an infrastructure one.
                          If you don’t have one of the two devices set up to accept incoming connections and with a way to know what IP address to connect to (via either static ip or registering with a DNS) then you can’t do it.
                          Neither of these conditions, however, depend on the application code, it’s just device setup

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          1 Reply Last reply
                          2
                          • SGaistS SGaist

                            Static address is not required if you have a DNS resolvable name.

                            Q Offline
                            Q Offline
                            qcoderpro
                            wrote on last edited by
                            #14

                            @SGaist

                            Static address is not required if you have a DNS resolvable name.

                            Although I've forgotten most of the things from university lessons (years ago) but yet can recall that a DNS works much like a phone book by managing the mapping between names and numbers. Do you mean that I need to setup a DNS resolvable name? Will you recommend a tutorial on this please?

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

                              Nobody suggested that you install a DNS server. You need to get an address from example from noip or another service.

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

                              Q 1 Reply Last reply
                              1
                              • SGaistS SGaist

                                Nobody suggested that you install a DNS server. You need to get an address from example from noip or another service.

                                Q Offline
                                Q Offline
                                qcoderpro
                                wrote on last edited by qcoderpro
                                #16

                                @SGaist
                                Aha, you mean to get an IP address from noip.com for instance, or another website like that.
                                But how that IP address will work on my projects, please?

                                jsulmJ 1 Reply Last reply
                                0
                                • Q qcoderpro

                                  @SGaist
                                  Aha, you mean to get an IP address from noip.com for instance, or another website like that.
                                  But how that IP address will work on my projects, please?

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

                                  @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                  But how that IP address will work on my projects, please?

                                  Your device will get the IP at runtime using DNS.
                                  If you access www..google..com you also do not enter an IP, right? But in the background your machine gets the IP for www..google..com via DNS.

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

                                  Q 1 Reply Last reply
                                  1
                                  • jsulmJ jsulm

                                    @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                    But how that IP address will work on my projects, please?

                                    Your device will get the IP at runtime using DNS.
                                    If you access www..google..com you also do not enter an IP, right? But in the background your machine gets the IP for www..google..com via DNS.

                                    Q Offline
                                    Q Offline
                                    qcoderpro
                                    wrote on last edited by
                                    #18

                                    @jsulm
                                    I mean, is the story this way?
                                    When both projects are run, the server will get the IP address (provided by noip.com). The client also has that address (in its code) so it connects to it. Then they can exchanges messages.
                                    Right?

                                    If so, how about the port number!? Don't we need it?

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • Q qcoderpro

                                      @jsulm
                                      I mean, is the story this way?
                                      When both projects are run, the server will get the IP address (provided by noip.com). The client also has that address (in its code) so it connects to it. Then they can exchanges messages.
                                      Right?

                                      If so, how about the port number!? Don't we need it?

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

                                      @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                      The client also has that address (in its code) so it connects to it

                                      Do you mean IP address? No, client also has to get the IP first.

                                      "If so, how about the port number!?" - port number can be fixed (like 8080 for HTTP).

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

                                      Q 1 Reply Last reply
                                      1
                                      • jsulmJ jsulm

                                        @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                        The client also has that address (in its code) so it connects to it

                                        Do you mean IP address? No, client also has to get the IP first.

                                        "If so, how about the port number!?" - port number can be fixed (like 8080 for HTTP).

                                        Q Offline
                                        Q Offline
                                        qcoderpro
                                        wrote on last edited by
                                        #20

                                        @jsulm
                                        OK so both projects need to get the IP address at runtime and since the port is set to 8080 (as you said), they can connect and start exchanging messages. Right?

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • Q qcoderpro

                                          @jsulm
                                          OK so both projects need to get the IP address at runtime and since the port is set to 8080 (as you said), they can connect and start exchanging messages. Right?

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

                                          @qcoderpro said in Extending networking/socket programming functionality of a qml project:

                                          as you said

                                          I did not. It was just an example.
                                          "they can connect and start exchanging messages" - if they can get the IP then yes.

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

                                          Q 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