QString mylocalip;
const QList interfaces = QNetworkInterface::allInterfaces();
foreach(QNetworkInterface ip, interfaces)
{
if (ip.humanReadableName() == QStringLiteral(“以太网”))
{
//if (ip.type() == QNetworkInterface::Ethernet)
{
const QList iplist = ip.addressEntries();
foreach(QNetworkAddressEntry net, iplist)
{
mylocalip = net.ip().toString();
}
}
}
}
udpSocket = new QUdpSocket(this);
udpSocket->bind(QHostAddress(mylocalip), 10004/, QUdpSocket::ShareAddress/);
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(VoiceReadyReadSlot()));
void VideoForm::VoiceReadyReadSlot()
{
video vp1;
int type = 0;
memset(&vp1, 0, sizeof(vp1));
while (udpSocket->hasPendingDatagrams()) {
//int len = udpSocket->pendingDatagramSize(); //获取字节数
//char* buf = new char[len];
udpSocket->readDatagram((char*)&vp1, sizeof(vp1));
}
if(udpSocket!=NULL)
udpSocket->writeDatagram((const char*)&vp, sizeof(vp), QHostAddress(friendip), 1004); //给对方发送
}