Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Qt Ethernet communication

    General and Desktop
    7
    19
    7439
    Loading More Posts
    • 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 last edited by 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.

      JKSH H 2 Replies Last reply Reply Quote 0
      • JKSH
        JKSH Moderators @neda last edited by

        @neda said in Qt Ethernet communication:

        I want to... send and receive data.

        What kind of data?

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

        • User Datagram Protocol (UDP)
        • HyperText Transfer Protocol (HTTP)
        • WebSocket
        • Modbus over TCP
        • Message Queuing Telemetry Transport (MQTT)
        • Data Distribution Service (DDS)

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

        If you use a standard communications protocol, the protocol might specify the port number (for example, HTTP usually uses Port 80).

        QTcpSocket is more for custom communications protocols. I recommend you ignore this and choose a standard protocol instead.

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

        N 1 Reply Last reply Reply Quote 2
        • aha_1980
          aha_1980 Lifetime Qt Champion last edited by

          Hi @neda, welcome!

          and just to add to @JKSH: Do you want to implement a server or a client? A server offers services and therefore listens on a port. A client connects to a port to access a server.

          Regards

          Qt has to stay free or it will die.

          N 1 Reply Last reply Reply Quote 2
          • N
            neda @JKSH last edited by 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.

            JKSH 1 Reply Last reply Reply Quote 0
            • N
              neda @aha_1980 last edited by

              @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_1980 1 Reply Last reply Reply Quote 0
              • aha_1980
                aha_1980 Lifetime Qt Champion @neda last edited by

                @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 Reply Quote 1
                • N
                  neda @aha_1980 last edited by

                  @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_1980 W 2 Replies Last reply Reply Quote 0
                  • aha_1980
                    aha_1980 Lifetime Qt Champion @neda last edited by

                    @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 Reply Quote 0
                    • JKSH
                      JKSH Moderators @neda last edited by

                      @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 Reply Quote 1
                      • N
                        neda @aha_1980 last edited by

                        @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 Reply Quote 0
                        • N
                          neda @JKSH last edited by 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();
                          
                          JKSH 1 Reply Last reply Reply Quote 0
                          • JKSH
                            JKSH Moderators @neda last edited by

                            @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 Reply Quote 5
                            • W
                              wrosecrans @neda last edited by

                              @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 Reply Quote 3
                              • N
                                neda @JKSH last edited by 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_1980 JKSH 2 Replies Last reply Reply Quote 0
                                • aha_1980
                                  aha_1980 Lifetime Qt Champion @neda last edited by

                                  @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 Reply Quote 3
                                  • mrjj
                                    mrjj Lifetime Qt Champion last edited by

                                    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 Reply Quote 4
                                    • K
                                      kuzulis Qt Champions 2020 last edited by

                                      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 Reply Quote 4
                                      • JKSH
                                        JKSH Moderators @neda last edited by

                                        @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 Reply Quote 4
                                        • H
                                          Hugh P @neda last edited by

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

                                          1 Reply Last reply Reply Quote 2
                                          • First post
                                            Last post