bool QXmppStream::sendData(const QByteArray &data) { logSent(QString::fromUtf8(data)); if (!d->socket || d->socket->state() != QAbstractSocket::ConnectedState) return false; return d->socket->write(data) == data.size(); }
void Messenger::onTimerdiscovery() { QString packet = PCK_HEADER "DISCOVERY:" + _mypeer.ID(); //QHostAddress target = QHostAddress("224.1.2.3"); //QHostAddress target = QHostAddress("192.168.0.255"); QHostAddress target = QHostAddress::Broadcast; logSent(packet, target); _udp.writeDatagram(packet.toUtf8(), target, 2880); // chekc for olds for(int i=0; i<_peers.count(); i++) if(_peers[i].Lastseen.secsTo(QTime::currentTime()) > 10) { _peers.removeAt(i); emit peersUpdated(); } // room list for(int i=0; i<_rooms.count(); i++) roomList(_rooms[i]); for(int i=0; i<_rooms.count(); i++) { QString room = _rooms[i]; if(!_roomslist.contains(room)) continue; for(int j=0; j<_roomslist[room].count(); j++) if(_roomslist[room].at(j).Lastseen.secsTo(QTime::currentTime()) > 10) { QString name = _roomslist[room][j].ID(); _roomslist[room].removeAt(j); emit roomListUpdated(room, "*** " + name + " Left. ***"); } } }
void Messenger::sendRoom(QString text, QString room) { QString packet = PCK_HEADER "ROOM:" + room + ":" + _mypeer.ID() + ":" + text; QHostAddress target = QHostAddress::Broadcast; logSent(packet, target); _udp.writeDatagram(packet.toUtf8(), target, 2880); }
void Messenger::roomList(QString room) { QString packet = PCK_HEADER "ROOMLIST:" + room + ":" + _mypeer.ID(); QHostAddress target = QHostAddress::Broadcast; logSent(packet, target); _udp.writeDatagram(packet.toUtf8(), target, 2880); }
void Messenger::sendPM(QString text, QString to) { QHostAddress adr = getIPbyID(to); QString packet = PCK_HEADER "PM:" + _mypeer.ID() + ":" + text; logSent(packet, adr); _udp.writeDatagram(packet.toUtf8(), adr, 2880); }