bool MyClass::Initialise()
{
struct servent *serv;
serv = getservbyname("multicast_in", "udp");
if(serv == NULL)
{
logging
->write
(LOG_ERR,
QString("Cannot find service multicast_in in /etc/services."));
error = true;
}
else
{
quint16 port = qFromBigEndian(uint16_t(serv->s_port));
{
joinMulticastGroup
(QString("mtrack"));
joinMulticastGroup
(QString("strack"));
connect(udpSocket, SIGNAL(readyRead()),this, SLOT(dataReceived()), Qt::DirectConnection);
}
else
{
logging
->write
(LOG_ERR,
QString("EFeed socket bind failed."));
error = true;
}
}
}
bool MyClass
::joinMulticastGroup(QString group
) {
bool error = false;
if(host.addresses().isEmpty())
{
logging
->write
(LOG_ERR,
QString("EFeed address for %1 not found.").
arg(group
));
error = true;
}
else
{
address = host.addresses().first();
logging
->write
(LOG_INFO,
QString("Joining multicast Group %1 Address %2").
arg(group
).
arg(address.
toString()));
if(udpSocket->joinMulticastGroup(address))
{
logging
->write
(LOG_INFO,
QString("EFeed socket join multicast group %1 successful.").
arg(group
));
}
else
{
logging
->write
(LOG_ERR,
QString("EFeed socket join multicast group %1 failed %2").
arg(group
).
arg(udpSocket
->errorString
()));
error = true;
}
}
return error;
}
}
bool MyClass::Initialise()
{
udpSocket = new QUdpSocket(this);
struct servent *serv;
serv = getservbyname("multicast_in", "udp");
if(serv == NULL)
{
logging->write(LOG_ERR, QString("Cannot find service multicast_in in /etc/services."));
error = true;
}
else
{
quint16 port = qFromBigEndian(uint16_t(serv->s_port));
if(udpSocket->bind(QHostAddress::AnyIPv4, port, QUdpSocket::ShareAddress) == true)
{
joinMulticastGroup(QString("mtrack"));
joinMulticastGroup(QString("strack"));
connect(udpSocket, SIGNAL(readyRead()),this, SLOT(dataReceived()), Qt::DirectConnection);
}
else
{
logging->write(LOG_ERR, QString("EFeed socket bind failed."));
error = true;
}
}
}
bool MyClass::joinMulticastGroup(QString group)
{
QHostAddress address;
bool error = false;
QHostInfo host = QHostInfo::fromName(group);
if(host.addresses().isEmpty())
{
logging->write(LOG_ERR, QString("EFeed address for %1 not found.").arg(group));
error = true;
}
else
{
address = host.addresses().first();
logging->write(LOG_INFO, QString("Joining multicast Group %1 Address %2").arg(group).arg(address.toString()));
if(udpSocket->joinMulticastGroup(address))
{
logging->write(LOG_INFO, QString("EFeed socket join multicast group %1 successful.").arg(group));
}
else
{
logging->write(LOG_ERR, QString("EFeed socket join multicast group %1 failed %2").arg(group).arg(udpSocket->errorString()));
error = true;
}
}
return error;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks