Problems filtering IP on QUdpSocket
Hi, im having some trouble working with UDP sockets.
On my computer, i have 2 programs I made with QT. Each one is supposed to recieve UDP datagrams from different IP directions. Lets say Program A recieves from IP 1 and Program B recieves from IP 2. Both IP transmit from the exact same port (6195)
The problem i have is that im not being able to filter the packages by IP, so Program A might recieve packages from IP 2, and the other way round.
If i make
I recieve from both IP, and this doesnt work.
If i do
I dont recieve anything at all. I have also tried
with the same result, I just dont recieve anything at all.
I know theres something here im not understanding, so id like if anyone could tell me how to filter an UDP package by IP, so that a Program wont interfere with the other one. Maybe not using a class, but using some C functions?
I cant filter by port, because both IP transmit with the same port.
Thanks in advance!
You can't filter based on the IP address @Server side. These two apps should be listening on different port numbers locally. Both apps will receive the packets. You need to get IP address at you apps side and then decide accept or reject. readDatagram(...) function says which IP address packet is received.
@qint64 QUdpSocket::readDatagram(char * data, qint64 maxSize, QHostAddress * address = 0, quint16 * port = 0)@
You check the address value and decide to process or reject the packet.
In summary, packet will be received by apps when sent from different IP address.