Qt Ethernet communication
-
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.
-
@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.
-
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. -
@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
-
@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.
-
@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();
-
@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:
- Physical
- Data Link (Ethernet, MAC addresses)
- Network (Internet Protocol, IP addresses)
- Transport (TCP)
- Session
- Presentation
- 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.
-
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.
-
@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.
-
as already said, Qt and we may not be much help in this case. but i have a small cookbook:
- get a book with the full Ethernet specification and make sure you completely understand layer 1 (MAC) and 2 (IP)
- implement your wish with operating system specific code by using OS (driver) API
-
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. -
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...
-
@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.
-
@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.