QT writeDatagram function return -1 when I tried to send data to specific IP Address

79 views Asked by At

I want to sending 8 byte data from PC(Linux) to another device. PC(Linux) IP : 10.100.40.99 Another Device IP: 10.100.40.62 Port: 7070

udpPacket_t udpPacket;
udpPacket.byte0 = 0x00;
udpPacket.byte1 = 0x00;
udpPacket.byte2 = 0x00;
udpPacket.byte3 = 0x00;
udpPacket.byte4 = 0x00;
udpPacket.byte5 = 0x00;
udpPacket.byte6 = 0x00;
udpPacket.byte7 = 0x00;

QByteArray data;
data.append(udpPacket.byte0);
data.append(udpPacket.byte1);
data.append(udpPacket.byte2);
data.append(udpPacket.byte3);
data.append(udpPacket.byte4);
data.append(udpPacket.byte5);
data.append(udpPacket.byte6);
data.append(udpPacket.byte7);

int ret = socket->writeDatagram(data, QHostAddress("10.100.40.62"), 7070);

writeDatagram function returns "-1". When I tried to send data to 10.100.40.255 IP Address. The data sends successfully. But when I tried to send data to specific IP Address instead of broadcast, writeDatagram returns -1. What am I missing ?

0

There are 0 answers