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 Update on Monday, May 27th 2025

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.
  • V Offline
    V Offline
    vishbynature
    wrote on last edited by
    #1

    Hello,
    As the title suggest i am trying to establish communication between RPi and local PC. so far i have not come across any documentation related to that. I have read about QTCPSOCKET but i dont have clear idea of how to do this. this is all completely new please help.
    Regards,

    J.HilkJ 1 Reply Last reply
    1
    • V vishbynature

      Hello,
      As the title suggest i am trying to establish communication between RPi and local PC. so far i have not come across any documentation related to that. I have read about QTCPSOCKET but i dont have clear idea of how to do this. this is all completely new please help.
      Regards,

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @vishbynature

      the fortune server and client

      seem like a good place to start.

      If you use QtCreator, then they are part of the ready to compile examples in it.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      8
      • M Offline
        M Offline
        MrShawn
        wrote on last edited by
        #3

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

        V 1 Reply Last reply
        4
        • M MrShawn

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

          V Offline
          V Offline
          vishbynature
          wrote on last edited by vishbynature
          #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)?

          aha_1980A 1 Reply Last reply
          1
          • V vishbynature

            @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)?

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @vishbynature do you mean QHostAddress::LocalHost ?

            Qt has to stay free or it will die.

            V 1 Reply Last reply
            1
            • aha_1980A aha_1980

              @vishbynature do you mean QHostAddress::LocalHost ?

              V Offline
              V Offline
              vishbynature
              wrote on last edited by vishbynature
              #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.........

              aha_1980A 1 Reply Last reply
              0
              • V vishbynature

                @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.........

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 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
                1
                • aha_1980A aha_1980

                  @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 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.

                  aha_1980A 1 Reply Last reply
                  0
                  • V vishbynature

                    @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.

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 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
                    5
                    • aha_1980A aha_1980

                      @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 last edited by vishbynature
                      #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?

                      aha_1980A 1 Reply Last reply
                      1
                      • V vishbynature

                        @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?

                        aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on 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
                        3
                        • aha_1980A aha_1980

                          @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 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