Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Ethernet communication between RPi and local PC
Forum Updated to NodeBB v4.3 + New Features

Ethernet communication between RPi and local PC

Scheduled Pinned Locked Moved Solved Mobile and Embedded
raspberry pi3ethernet in qtqtcpsocketqt 5.9.0
12 Posts 4 Posters 2.1k 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 Offline
    M Offline
    MrShawn
    wrote on 7 Jun 2019, 13:55 last edited by
    #3

    Search "TCP server Voidrealms" on youtube. That might help get you started as well.

    V 1 Reply Last reply 9 Jul 2019, 07:30
    4
    • M MrShawn
      7 Jun 2019, 13:55

      Search "TCP server Voidrealms" on youtube. That might help get you started as well.

      V Offline
      V Offline
      vishbynature
      wrote on 9 Jul 2019, 07:30 last edited by vishbynature 7 Sept 2019, 07:31
      #4

      @MrShawn @J-Hilk
      thank you for your replies.
      i followed the tutorial at bogotobogo and was able to establish connection. Now in my code following line:
      server->listen(QHostAddress::Any, 1234);
      makes the server to listen to all connections on port 1234. how to make it always listen to only one connection (local PC)?

      A 1 Reply Last reply 9 Jul 2019, 12:15
      1
      • V vishbynature
        9 Jul 2019, 07:30

        @MrShawn @J-Hilk
        thank you for your replies.
        i followed the tutorial at bogotobogo and was able to establish connection. Now in my code following line:
        server->listen(QHostAddress::Any, 1234);
        makes the server to listen to all connections on port 1234. how to make it always listen to only one connection (local PC)?

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 9 Jul 2019, 12:15 last edited by
        #5

        @vishbynature do you mean QHostAddress::LocalHost ?

        Qt has to stay free or it will die.

        V 1 Reply Last reply 9 Jul 2019, 14:30
        1
        • A aha_1980
          9 Jul 2019, 12:15

          @vishbynature do you mean QHostAddress::LocalHost ?

          V Offline
          V Offline
          vishbynature
          wrote on 9 Jul 2019, 14:30 last edited by vishbynature 7 Sept 2019, 14:31
          #6

          @aha_1980
          i tried that before and I get "no connection could be made because the target machine actively refused it." at client side.
          Any and AnyIPv4 work normally and using ipv4 at client side by the way. Still working on server to listen only to PC.........

          A 1 Reply Last reply 9 Jul 2019, 15:03
          0
          • V vishbynature
            9 Jul 2019, 14:30

            @aha_1980
            i tried that before and I get "no connection could be made because the target machine actively refused it." at client side.
            Any and AnyIPv4 work normally and using ipv4 at client side by the way. Still working on server to listen only to PC.........

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 9 Jul 2019, 15:03 last edited by
            #7

            @vishbynature said in Ethernet communication between RPi and local PC:

            Still working on server to listen only to PC.........

            Maybe you should rephrase your question. LocalHost means Server and Client run on the same machine.

            It sounds like that is not what you want. What do you want then?

            Regards

            Qt has to stay free or it will die.

            V 1 Reply Last reply 10 Jul 2019, 07:44
            1
            • A aha_1980
              9 Jul 2019, 15:03

              @vishbynature said in Ethernet communication between RPi and local PC:

              Still working on server to listen only to PC.........

              Maybe you should rephrase your question. LocalHost means Server and Client run on the same machine.

              It sounds like that is not what you want. What do you want then?

              Regards

              V Offline
              V Offline
              vishbynature
              wrote on 10 Jul 2019, 07:44 last edited by
              #8

              @aha_1980
              ok I get what you say.
              I am able to create server at RPi which listens to connections and after serving first client ( PC ), it disconnects and waits for new connection. i want it to stay connected to the same client and not look for another connection.

              A 1 Reply Last reply 10 Jul 2019, 08:37
              0
              • V vishbynature
                10 Jul 2019, 07:44

                @aha_1980
                ok I get what you say.
                I am able to create server at RPi which listens to connections and after serving first client ( PC ), it disconnects and waits for new connection. i want it to stay connected to the same client and not look for another connection.

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 10 Jul 2019, 08:37 last edited by
                #9

                @vishbynature said in Ethernet communication between RPi and local PC:

                i want it to stay connected to the same client

                ... then just make sure that not one side (PC or RPi) disconnects for some reason.

                and not look for another connection.

                So effectively you want to limit your server to one connection at a time. Looks like: https://stackoverflow.com/questions/35926188/qt-tcpserver-max-clients where the answer from peppe states:

                "Do not call nextPendingConnection if you're already handling enough clients."

                I think that is what you should do.

                Regards

                Qt has to stay free or it will die.

                V 1 Reply Last reply 11 Jul 2019, 09:17
                5
                • A aha_1980
                  10 Jul 2019, 08:37

                  @vishbynature said in Ethernet communication between RPi and local PC:

                  i want it to stay connected to the same client

                  ... then just make sure that not one side (PC or RPi) disconnects for some reason.

                  and not look for another connection.

                  So effectively you want to limit your server to one connection at a time. Looks like: https://stackoverflow.com/questions/35926188/qt-tcpserver-max-clients where the answer from peppe states:

                  "Do not call nextPendingConnection if you're already handling enough clients."

                  I think that is what you should do.

                  Regards

                  V Offline
                  V Offline
                  vishbynature
                  wrote on 11 Jul 2019, 09:17 last edited by vishbynature 7 Nov 2019, 09:17
                  #10

                  @aha_1980
                  yes I agree, my code is exactly the same.
                  but if you remove nextpendingconnection line then they simply don't communicate. I tried to replace it with other member functions of QTcpServer but This piece of code is essential in the end.
                  what should i replace it with then?

                  A 1 Reply Last reply 11 Jul 2019, 10:15
                  1
                  • V vishbynature
                    11 Jul 2019, 09:17

                    @aha_1980
                    yes I agree, my code is exactly the same.
                    but if you remove nextpendingconnection line then they simply don't communicate. I tried to replace it with other member functions of QTcpServer but This piece of code is essential in the end.
                    what should i replace it with then?

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 11 Jul 2019, 10:15 last edited by
                    #11

                    @vishbynature

                    If your re-read my post you will notice that I didn't say, you should remove or replace nextPendingConnection().

                    I rather said, if you have enough clients, then don't accept further ones by not calling nextPendingConnection(). In your case that would mean you call it only one time for the first connection.

                    Qt has to stay free or it will die.

                    V 1 Reply Last reply 12 Jul 2019, 08:47
                    3
                    • A aha_1980
                      11 Jul 2019, 10:15

                      @vishbynature

                      If your re-read my post you will notice that I didn't say, you should remove or replace nextPendingConnection().

                      I rather said, if you have enough clients, then don't accept further ones by not calling nextPendingConnection(). In your case that would mean you call it only one time for the first connection.

                      V Offline
                      V Offline
                      vishbynature
                      wrote on 12 Jul 2019, 08:47 last edited by
                      #12

                      @aha_1980
                      ok, i understood what you said.

                      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