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. Running Qt Example client/server not working
QtWS25 Last Chance

Running Qt Example client/server not working

Scheduled Pinned Locked Moved Solved General and Desktop
networkclientserverqtnetwork
17 Posts 3 Posters 7.6k Views
  • 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.
  • M marlenet15
    19 Jul 2016, 18:16

    It does not crash. After I click the button "get fortune", nothing happens. From what I read in the code, if the client was not able to find the server then it would output that it was not able to find it. However, I get no errors back at all.

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 19 Jul 2016, 18:19 last edited by
    #4

    @marlenet15
    That's strange. Is it possible the connection times out? What happens if you wait a little? Could you check (if running on windows for example) that there's no system tool that interferes with the network connection?

    Kind regards.

    Read and abide by the Qt Code of Conduct

    M 1 Reply Last reply 19 Jul 2016, 18:33
    1
    • K kshegunov
      19 Jul 2016, 18:19

      @marlenet15
      That's strange. Is it possible the connection times out? What happens if you wait a little? Could you check (if running on windows for example) that there's no system tool that interferes with the network connection?

      Kind regards.

      M Offline
      M Offline
      marlenet15
      wrote on 19 Jul 2016, 18:33 last edited by
      #5

      @kshegunov I have been waiting for at least 5 minutes and nothing happens. I am running Qt on Linux and I don't think anything is interfering it.

      1 Reply Last reply
      0
      • M marlenet15
        19 Jul 2016, 18:16

        It does not crash. After I click the button "get fortune", nothing happens. From what I read in the code, if the client was not able to find the server then it would output that it was not able to find it. However, I get no errors back at all.

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 19 Jul 2016, 18:34 last edited by mrjj
        #6

        @marlenet15

        Hi
        The IP the server find/shows might not be valid.
        for me it was not. (just ran the samples)
        use localhost for client
        and it works for me.

        That ip is not my local IP, nor my wan.
        No interface seems to have it.

        So be sure the IP it shows is correct :)

        M 1 Reply Last reply 19 Jul 2016, 18:53
        0
        • M mrjj
          19 Jul 2016, 18:34

          @marlenet15

          Hi
          The IP the server find/shows might not be valid.
          for me it was not. (just ran the samples)
          use localhost for client
          and it works for me.

          That ip is not my local IP, nor my wan.
          No interface seems to have it.

          So be sure the IP it shows is correct :)

          M Offline
          M Offline
          marlenet15
          wrote on 19 Jul 2016, 18:53 last edited by
          #7

          @mrjj On terminal I ran ifconfig and under wlan it shows the ip address that is shown on the fortune server. So what you are using is to use 127.0.0.1 on the client and server side as the ip address? Because that doesn't work either. :/

          M 1 Reply Last reply 19 Jul 2016, 18:57
          0
          • M marlenet15
            19 Jul 2016, 18:53

            @mrjj On terminal I ran ifconfig and under wlan it shows the ip address that is shown on the fortune server. So what you are using is to use 127.0.0.1 on the client and server side as the ip address? Because that doesn't work either. :/

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 19 Jul 2016, 18:57 last edited by mrjj
            #8

            @marlenet15
            Ok so in linux it find right ip I guess. ( im on win)
            yes local host is that 127.x.x.x ip.
            And i use it for server IP. + the listed port.

            Are u running both samples on same machine?

            It works here both for win 7 and win 10.

            M 1 Reply Last reply 19 Jul 2016, 19:09
            1
            • M mrjj
              19 Jul 2016, 18:57

              @marlenet15
              Ok so in linux it find right ip I guess. ( im on win)
              yes local host is that 127.x.x.x ip.
              And i use it for server IP. + the listed port.

              Are u running both samples on same machine?

              It works here both for win 7 and win 10.

              M Offline
              M Offline
              marlenet15
              wrote on 19 Jul 2016, 19:09 last edited by
              #9

              @mrjj I am doing exactly as you are telling me but nothing. Also, I am using Threaded Fortune Server. Are you using that as well?

              So in my Threaded Fortune Server I have :
              IP: 192.168.1.209
              port: 45127

              In my fortune client I have:
              Server name: localhost
              port: 45127

              M K 2 Replies Last reply 19 Jul 2016, 19:26
              0
              • M marlenet15
                19 Jul 2016, 19:09

                @mrjj I am doing exactly as you are telling me but nothing. Also, I am using Threaded Fortune Server. Are you using that as well?

                So in my Threaded Fortune Server I have :
                IP: 192.168.1.209
                port: 45127

                In my fortune client I have:
                Server name: localhost
                port: 45127

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 19 Jul 2016, 19:26 last edited by
                #10

                @marlenet15
                nope, im using the "simple" ones.

                local host should work if both server and client is run on same machine.

                I will check tomorrow when i have a linux to see.

                1 Reply Last reply
                0
                • M marlenet15
                  19 Jul 2016, 19:09

                  @mrjj I am doing exactly as you are telling me but nothing. Also, I am using Threaded Fortune Server. Are you using that as well?

                  So in my Threaded Fortune Server I have :
                  IP: 192.168.1.209
                  port: 45127

                  In my fortune client I have:
                  Server name: localhost
                  port: 45127

                  K Offline
                  K Offline
                  kshegunov
                  Moderators
                  wrote on 19 Jul 2016, 19:35 last edited by
                  #11

                  @marlenet15
                  That's really, really strange. Could you run the client code through the debugger? What would be the TCP error the client gets?
                  (I don't have Qt 4 to test, sorry).

                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  M 1 Reply Last reply 19 Jul 2016, 19:55
                  0
                  • K kshegunov
                    19 Jul 2016, 19:35

                    @marlenet15
                    That's really, really strange. Could you run the client code through the debugger? What would be the TCP error the client gets?
                    (I don't have Qt 4 to test, sorry).

                    Kind regards.

                    M Offline
                    M Offline
                    marlenet15
                    wrote on 19 Jul 2016, 19:55 last edited by
                    #12

                    @kshegunov Ok So I used the regular Fortune Server and it works. So I am wondering why with the Threaded Fortune Server it does not work. The thing is I need to use threaded server.

                    K 1 Reply Last reply 19 Jul 2016, 20:11
                    0
                    • M marlenet15
                      19 Jul 2016, 19:55

                      @kshegunov Ok So I used the regular Fortune Server and it works. So I am wondering why with the Threaded Fortune Server it does not work. The thing is I need to use threaded server.

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 19 Jul 2016, 20:11 last edited by
                      #13

                      @marlenet15 said:

                      So I am wondering why with the Threaded Fortune Server it does not work. The thing is I need to use threaded server.

                      Well, perhaps the example is broken; it has happened. But in any case the threaded fortune server is not really a good example of a threaded TCP server, not for real work anyway.

                      Kind regards.

                      Read and abide by the Qt Code of Conduct

                      M 1 Reply Last reply 19 Jul 2016, 20:20
                      1
                      • K kshegunov
                        19 Jul 2016, 20:11

                        @marlenet15 said:

                        So I am wondering why with the Threaded Fortune Server it does not work. The thing is I need to use threaded server.

                        Well, perhaps the example is broken; it has happened. But in any case the threaded fortune server is not really a good example of a threaded TCP server, not for real work anyway.

                        Kind regards.

                        M Offline
                        M Offline
                        marlenet15
                        wrote on 19 Jul 2016, 20:20 last edited by
                        #14

                        @kshegunov Do you know of any good examples? Thank you.

                        K 1 Reply Last reply 19 Jul 2016, 20:34
                        0
                        • M marlenet15
                          19 Jul 2016, 20:20

                          @kshegunov Do you know of any good examples? Thank you.

                          K Offline
                          K Offline
                          kshegunov
                          Moderators
                          wrote on 19 Jul 2016, 20:34 last edited by
                          #15

                          @marlenet15
                          Honestly, no. But I was about to write something as an example for a library of mine, so I'll post when I have it.
                          Meanwhile, you should look up how to use the asynchronous TCP socket API in Qt and make your code work in single thread. Look here for example. When that's done it takes very little modification to make it work in multiple threads.

                          Kind regards.

                          Read and abide by the Qt Code of Conduct

                          M 1 Reply Last reply 19 Jul 2016, 20:53
                          1
                          • K kshegunov
                            19 Jul 2016, 20:34

                            @marlenet15
                            Honestly, no. But I was about to write something as an example for a library of mine, so I'll post when I have it.
                            Meanwhile, you should look up how to use the asynchronous TCP socket API in Qt and make your code work in single thread. Look here for example. When that's done it takes very little modification to make it work in multiple threads.

                            Kind regards.

                            M Offline
                            M Offline
                            marlenet15
                            wrote on 19 Jul 2016, 20:53 last edited by
                            #16

                            @kshegunov Thank you so much!

                            K 1 Reply Last reply 21 Jul 2016, 22:13
                            0
                            • M marlenet15
                              19 Jul 2016, 20:53

                              @kshegunov Thank you so much!

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 21 Jul 2016, 22:13 last edited by kshegunov
                              #17

                              @marlenet15
                              Hi,
                              Here you can find a threaded TCP server example. You can ignore the module specific classes QDaemonApplication (think of it as QCoreApplication) and QDaemonLog you can substitute with QDebug.

                              Enjoy!
                              Kind regards.

                              Read and abide by the Qt Code of Conduct

                              1 Reply Last reply
                              2

                              13/17

                              19 Jul 2016, 20:11

                              • Login

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