void DuktoProtocol::sayHello(QHostAddress dest, qint16 port) { // Preparazione pacchetto QByteArray *packet = new QByteArray(); if ((port == DEFAULT_UDP_PORT) && (mLocalUdpPort == DEFAULT_UDP_PORT)) { if (dest == QHostAddress::Broadcast) packet->append(0x01); // 0x01 -> HELLO MESSAGE (broadcast) else packet->append(0x02); // 0x02 -> HELLO MESSAGE (unicast) } else { if (dest == QHostAddress::Broadcast) packet->append(0x04); // 0x04 -> HELLO MESSAGE (broadcast) with PORT else packet->append(0x05); // 0x05 -> HELLO MESSAGE (unicast) with PORT packet->append((char*)&mLocalUdpPort, sizeof(qint16)); } packet->append(getSystemSignature()); // Invio pacchetto if (dest == QHostAddress::Broadcast) { sendToAllBroadcast(packet, port); if (port != DEFAULT_UDP_PORT) sendToAllBroadcast(packet, DEFAULT_UDP_PORT); } else mSocket->writeDatagram(packet->data(), packet->length(), dest, port); delete packet; }
void DuktoProtocol::sayHello(QHostAddress dest, qint16 port) { // Preparazione pacchetto QByteArray packet; if ((port == DEFAULT_UDP_PORT) && (mLocalUdpPort == DEFAULT_UDP_PORT)) { if (dest == QHostAddress::Broadcast) packet.append(MSG_HELLO_BROADCAST); else packet.append(MSG_HELLO_UNICAST); } else { if (dest == QHostAddress::Broadcast) packet.append(MSG_HELLO_PORT_BROADCAST); else packet.append(MSG_HELLO_PORT_BROADCAST); packet.append((char*)&mLocalUdpPort, sizeof(qint16)); } packet.append(getSystemSignature()); // Invio pacchetto if (dest == QHostAddress::Broadcast) { QList<qint16> ports; ports.append(DEFAULT_UDP_PORT); if (port != DEFAULT_UDP_PORT) ports.append(port); sendToAllBroadcast(packet, ports); } else mSocket->writeDatagram(packet.data(), packet.length(), dest, port); }
void DuktoProtocol::sayGoodbye() { QByteArray *packet = new QByteArray(); packet->append(0x03); // 0x03 -> GOODBYE MESSAGE packet->append("Bye Bye"); sendToAllBroadcast(packet); delete packet; }
void DuktoProtocol::sayGoodbye() { // Create packet QByteArray packet; packet.append(MSG_GOODBYE); // Look for all the discovered ports QList<qint16> ports; ports.append(mLocalUdpPort); if (mLocalUdpPort != DEFAULT_UDP_PORT) ports.append(DEFAULT_UDP_PORT); QList<Peer> values = mPeers.values(); for(QList<Peer>::const_iterator p = values.constBegin(); p != values.constEnd(); ++p) if(!ports.contains(p->port)) ports.append(p->port); // Send broadcast message to all discovered ports sendToAllBroadcast(packet, ports); }
void DuktoProtocol::sayHello(QHostAddress dest) { // Preparazione pacchetto QByteArray *packet = new QByteArray(); if (dest == QHostAddress::Broadcast) packet->append(0x01); // 0x01 -> HELLO MESSAGE (broadcast) else packet->append(0x02); // 0x02 -> HELLO MESSAGE (unicast) packet->append(OsLib::retrieveSystemName()); // Invio pacchetto if (dest == QHostAddress::Broadcast) sendToAllBroadcast(packet); else mSocket->writeDatagram(packet->data(), packet->length(), dest, UDP_PORT); delete packet; }
void DuktoProtocol::sayGoodbye() { // Create packet QByteArray *packet = new QByteArray(); packet->append(0x03); // 0x03 -> GOODBYE MESSAGE packet->append("Bye Bye"); // Look for all the discovered ports QList<qint16> ports; ports.append(mLocalUdpPort); if (mLocalUdpPort != DEFAULT_UDP_PORT) ports.append(DEFAULT_UDP_PORT); foreach (const Peer &p, mPeers.values()) if (!ports.contains(p.port)) ports.append(p.port); // Send broadcast message to all discovered ports foreach (const qint16 &port, ports) sendToAllBroadcast(packet, port); // Free memory delete packet; }