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. Qt Ethernet communication
Forum Updated to NodeBB v4.3 + New Features

Qt Ethernet communication

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 9 Posters 10.8k 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.
  • N neda

    @aha_1980 said in Qt Ethernet communication:

    Do you want to implement a server or a client?

    I do not have a real server or client.

    Each of the two sides can begin to send or receive data.

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

    @neda said in Qt Ethernet communication:

    Each of the two sides can begin to send or receive data.

    Ok, understood.

    In this case, either both sides are client and server, or one side provides a server and a client and the other one only the client.

    As said, you need to listen on a port to be able to connect to this machine.

    Regards

    Qt has to stay free or it will die.

    N 1 Reply Last reply
    1
    • aha_1980A aha_1980

      @neda said in Qt Ethernet communication:

      Each of the two sides can begin to send or receive data.

      Ok, understood.

      In this case, either both sides are client and server, or one side provides a server and a client and the other one only the client.

      As said, you need to listen on a port to be able to connect to this machine.

      Regards

      N Offline
      N Offline
      neda
      wrote on last edited by
      #7

      @aha_1980 said in Qt Ethernet communication:

      As said, you need to listen on a port to be able to connect to this machine.

      Thanks
      Should I use the "QTcpSocket" class? or another class?

      aha_1980A W 2 Replies Last reply
      0
      • N neda

        @aha_1980 said in Qt Ethernet communication:

        As said, you need to listen on a port to be able to connect to this machine.

        Thanks
        Should I use the "QTcpSocket" class? or another class?

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

        @neda

        ... that depends a bit on what you want to achive. Which kind of data do you want to exchange?

        Qt has to stay free or it will die.

        N 1 Reply Last reply
        0
        • N neda

          Thanks for your reply.

          @JKSH said in Qt Ethernet communication:

          What communications protocol do you want to use? There are many different ways to send/receive data over Ethernet. For example:

          No, none.

          @JKSH said in Qt Ethernet communication:

          What kind of data?

          I want to send some bytes from device to computer.
          Computer and device connected with a network cable.
          I do not use any communications protocol.

          I have just "Mac Address" of my device.
          My device use "IEEE 802.3" standard.

          JKSHJ Online
          JKSHJ Online
          JKSH
          Moderators
          wrote on last edited by
          #9

          @neda said in Qt Ethernet communication:

          I do not use any communications protocol.

          "Communications protocol" means "A way to transfer data or messages between devices".

          If you don't want to use a standard communications protocol, then you must create your own custom communications protocol.

          I have just "Mac Address" of my device.

          A MAC address is not enough. You must find the IP address.

          You must also make sure that both devices are on the same subnet (this means both devices must have similar IP addresses).

          My device use "IEEE 11027" standard.

          Can you provide a link to "IEEE 11027"?

          @neda said in Qt Ethernet communication:

          Should I use the "QTcpSocket" class? or another class?

          You can use QTcpSocket if you know the device's IP address.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          N 1 Reply Last reply
          1
          • aha_1980A aha_1980

            @neda

            ... that depends a bit on what you want to achive. Which kind of data do you want to exchange?

            N Offline
            N Offline
            neda
            wrote on last edited by
            #10

            @aha_1980 said in Qt Ethernet communication:

            Which kind of data do you want to exchange?

            120 Bytes in per send.

            1 Reply Last reply
            0
            • JKSHJ JKSH

              @neda said in Qt Ethernet communication:

              I do not use any communications protocol.

              "Communications protocol" means "A way to transfer data or messages between devices".

              If you don't want to use a standard communications protocol, then you must create your own custom communications protocol.

              I have just "Mac Address" of my device.

              A MAC address is not enough. You must find the IP address.

              You must also make sure that both devices are on the same subnet (this means both devices must have similar IP addresses).

              My device use "IEEE 11027" standard.

              Can you provide a link to "IEEE 11027"?

              @neda said in Qt Ethernet communication:

              Should I use the "QTcpSocket" class? or another class?

              You can use QTcpSocket if you know the device's IP address.

              N Offline
              N Offline
              neda
              wrote on last edited by neda
              #11

              @JKSH said in Qt Ethernet communication:

              this means both devices must have similar IP addresses

              Exactly
              I do not want to go into the issues related to IP.
              That's why I want to use "MAC address".

              @JKSH said in Qt Ethernet communication:

              Can you provide a link to "IEEE 11027"?

              Sorry, it was a typo.
              "IEEE 802.3"
              https://en.wikipedia.org/wiki/Ethernet_frame

              @JKSH said in Qt Ethernet communication:

              You must find the IP address.

              No problem. I can find it.

              foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
                  {
                      if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack))
                          foreach (QNetworkAddressEntry entry, interface.addressEntries())
                          {                
                                  if(interface.hardwareAddress() == "61:5F:60:78:69:03"){
                                  qDebug()<<interface.hardwareAddress();
                                  qDebug()<<interface.name();
                                  qDebug()<<entry.ip();
              
              JKSHJ 1 Reply Last reply
              0
              • N neda

                @JKSH said in Qt Ethernet communication:

                this means both devices must have similar IP addresses

                Exactly
                I do not want to go into the issues related to IP.
                That's why I want to use "MAC address".

                @JKSH said in Qt Ethernet communication:

                Can you provide a link to "IEEE 11027"?

                Sorry, it was a typo.
                "IEEE 802.3"
                https://en.wikipedia.org/wiki/Ethernet_frame

                @JKSH said in Qt Ethernet communication:

                You must find the IP address.

                No problem. I can find it.

                foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
                    {
                        if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack))
                            foreach (QNetworkAddressEntry entry, interface.addressEntries())
                            {                
                                    if(interface.hardwareAddress() == "61:5F:60:78:69:03"){
                                    qDebug()<<interface.hardwareAddress();
                                    qDebug()<<interface.name();
                                    qDebug()<<entry.ip();
                
                JKSHJ Online
                JKSHJ Online
                JKSH
                Moderators
                wrote on last edited by
                #12

                @neda said in Qt Ethernet communication:

                I do not want to go into the issues related to IP.
                That's why I want to use "MAC address".

                See http://3.bp.blogspot.com/-BU-xe38B1qc/Ufavge5wj7I/AAAAAAAAAzg/jNuL7k2bY_0/s1600/OSI-TCP-Model-v1.png. These are the 7 layers of the Open System Interconnection model:

                1. Physical
                2. Data Link (Ethernet, MAC addresses)
                3. Network (Internet Protocol, IP addresses)
                4. Transport (TCP)
                5. Session
                6. Presentation
                7. Application

                You said you want to use only Ethernet and MAC addresses (Layer 2).

                If you don't want to use IP address (Layer 3), that means you cannot use TCP (Layer 4). TCP requires IP to work.

                That also means you must implement your own Network layer to replace IP. If your devices run Linux, you must write kernel drivers. This is a lot of work; do you want to continue?

                @neda said in Qt Ethernet communication:

                @JKSH said in Qt Ethernet communication:

                You must find the IP address.

                No problem. I can find it.

                foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
                

                This code only finds the network adaptors (and IP addresses) on the device that runs this code. It does not find other devices for you to send/receive data.

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                N 1 Reply Last reply
                5
                • N neda

                  @aha_1980 said in Qt Ethernet communication:

                  As said, you need to listen on a port to be able to connect to this machine.

                  Thanks
                  Should I use the "QTcpSocket" class? or another class?

                  W Offline
                  W Offline
                  wrosecrans
                  wrote on last edited by
                  #13

                  @neda

                  You won't be able to use QTcpSocket if you don't want to use a TCP connection. If you want to implement your own low level protocol on raw ethernet that doesn't use TCP/IP, there probably isn't much in Qt that you can use. Depending on the platform, you may need to write some low level driver code to do that. It's not even guaranteed to be possible entirely in user space.

                  1 Reply Last reply
                  3
                  • JKSHJ JKSH

                    @neda said in Qt Ethernet communication:

                    I do not want to go into the issues related to IP.
                    That's why I want to use "MAC address".

                    See http://3.bp.blogspot.com/-BU-xe38B1qc/Ufavge5wj7I/AAAAAAAAAzg/jNuL7k2bY_0/s1600/OSI-TCP-Model-v1.png. These are the 7 layers of the Open System Interconnection model:

                    1. Physical
                    2. Data Link (Ethernet, MAC addresses)
                    3. Network (Internet Protocol, IP addresses)
                    4. Transport (TCP)
                    5. Session
                    6. Presentation
                    7. Application

                    You said you want to use only Ethernet and MAC addresses (Layer 2).

                    If you don't want to use IP address (Layer 3), that means you cannot use TCP (Layer 4). TCP requires IP to work.

                    That also means you must implement your own Network layer to replace IP. If your devices run Linux, you must write kernel drivers. This is a lot of work; do you want to continue?

                    @neda said in Qt Ethernet communication:

                    @JKSH said in Qt Ethernet communication:

                    You must find the IP address.

                    No problem. I can find it.

                    foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
                    

                    This code only finds the network adaptors (and IP addresses) on the device that runs this code. It does not find other devices for you to send/receive data.

                    N Offline
                    N Offline
                    neda
                    wrote on last edited by neda
                    #14

                    @JKSH said in Qt Ethernet communication:

                    If your devices run Linux

                    Windows 10

                    @JKSH said in Qt Ethernet communication:

                    you must write kernel drivers. This is a lot of work; do you want to continue?

                    yes, please help me.

                    aha_1980A JKSHJ 2 Replies Last reply
                    0
                    • N neda

                      @JKSH said in Qt Ethernet communication:

                      If your devices run Linux

                      Windows 10

                      @JKSH said in Qt Ethernet communication:

                      you must write kernel drivers. This is a lot of work; do you want to continue?

                      yes, please help me.

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

                      @neda,

                      as already said, Qt and we may not be much help in this case. but i have a small cookbook:

                      1. get a book with the full Ethernet specification and make sure you completely understand layer 1 (MAC) and 2 (IP)
                      2. implement your wish with operating system specific code by using OS (driver) API

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      3
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        Hi
                        Why on earth dont you just use normal TCP with ip ?

                        Writing a custom network driver is extremely complex and
                        you will need heaps of knowledge about network stacks.
                        It seems silly to send some bytes.

                        1 Reply Last reply
                        4
                        • K Offline
                          K Offline
                          kuzulis
                          Qt Champions 2020
                          wrote on last edited by
                          #17

                          You can look on: https://www.codeproject.com/Articles/5292/Raw-Ethernet-Packet-Sending or try to use a libpcap (seems it should work) and then wrap your C++ code to use in Qt. A more info you can get from the internet, don't be lazy...

                          1 Reply Last reply
                          4
                          • N neda

                            @JKSH said in Qt Ethernet communication:

                            If your devices run Linux

                            Windows 10

                            @JKSH said in Qt Ethernet communication:

                            you must write kernel drivers. This is a lot of work; do you want to continue?

                            yes, please help me.

                            JKSHJ Online
                            JKSHJ Online
                            JKSH
                            Moderators
                            wrote on last edited by
                            #18

                            @neda said in Qt Ethernet communication:

                            @JKSH said in Qt Ethernet communication:

                            you must write kernel drivers. This is a lot of work; do you want to continue?

                            yes, please help me.

                            This is asking for a lot of help. If you don't want to use TCP/IP, then you need many months to develop a replacement. You must do most of the work yourself, you can't ask us to do it for you.

                            Please read the latest posts by @aha_1980, @mrjj, and @kuzulis and think through them carefully.

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            4
                            • N neda

                              I connect my computer to a wired (Ethernet) network.
                              I have "mac address".
                              I want to connect to this network with "mac address" and send and receive data.

                              I used "QTcpSocket" class and "connectToHost" function. But I haven't port number.

                              Please guide me.

                              H Offline
                              H Offline
                              Hugh P
                              wrote on last edited by
                              #19

                              @neda I have used libtins (and libpcap) for just this - to communicate with FPGAs that have a certain MAC address. It has worked well for me. https://github.com/mfontanini/libtins - I know the topic is old, but it is not an insane amount of work as others have indicated. You can send packets and filter for the desired MAC address.

                              H 1 Reply Last reply
                              2
                              • H Hugh P

                                @neda I have used libtins (and libpcap) for just this - to communicate with FPGAs that have a certain MAC address. It has worked well for me. https://github.com/mfontanini/libtins - I know the topic is old, but it is not an insane amount of work as others have indicated. You can send packets and filter for the desired MAC address.

                                H Offline
                                H Offline
                                Hedayat
                                wrote on last edited by
                                #20

                                @Hugh-P
                                Finally, I could find a good reply! :)) I want to send a layer 2 Frame (not a layer3 packet or upper layers of OSI message) from an android device to my electronic board. Do you have any suggestion?

                                Thanks a lot!

                                C 1 Reply Last reply
                                0
                                • H Hedayat

                                  @Hugh-P
                                  Finally, I could find a good reply! :)) I want to send a layer 2 Frame (not a layer3 packet or upper layers of OSI message) from an android device to my electronic board. Do you have any suggestion?

                                  Thanks a lot!

                                  C Offline
                                  C Offline
                                  ChrisW67
                                  wrote on last edited by
                                  #21

                                  Read the "good reply" by Hugh-P, or adapt from the earlier reply by kuzulis

                                  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