示例#1
0
文件: u3HClient.cpp 项目: und3ath/u3h
void u3HClient::DeserializeData(QByteArray & arrayRef)
{
	char * dataPtr = arrayRef.data();
	PACKET *packet = new PACKET();
	memcpy(packet, dataPtr, PACKET_SIZE_WDATA);
	if(packet->dwDataSize > 0) 
	{
		packet->data = static_cast<unsigned char *>(calloc(sizeof(unsigned char), packet->dwDataSize));
		switch (packet->dataType) 
		{
			case _string: 
			{
				dataPtr[PACKET_SIZE_WDATA + packet->dwDataSize ]  = '\0';
				strcpy((char*)packet->data, dataPtr + PACKET_SIZE_WDATA);
				break;
			}
			case _bytes: 
			{
				memcpy(packet->data, dataPtr + PACKET_SIZE_WDATA, packet->dwDataSize);
				break;
			}
		}
	}


	if (packet->_header.Command == _hello) 
	{
		emit HelloClient(this, packet);
	}
	else 
	{
		emit PacketReady(packet);
	}

}
示例#2
0
文件: u3HClient.cpp 项目: und3ath/u3h
void u3HClient::on_clientSocket_DataReady()
{
	if (!m_clientSocket->isReadable())
	{
		return;
	}

	PACKET *packet = new PACKET();
	QByteArray packetRaw = m_clientSocket->read(PACKET_SIZE_WDATA);

	if (packetRaw.size() < PACKET_SIZE_WDATA) 
	{

	}

	memcpy(packet, packetRaw.data(), PACKET_SIZE_WDATA);
	QByteArray dataRaw;
	if (packet->dwDataSize > 0) 
	{
		packet->data = static_cast<unsigned char *>(calloc(sizeof(unsigned char), packet->dwDataSize));
		
		while (dataRaw.size() < packet->dwDataSize)
		{
			dataRaw.append(m_clientSocket->readAll());
			if (dataRaw.size() < packet->dwDataSize)
				m_clientSocket->waitForReadyRead();
		}

		memcpy(packet->data, dataRaw.data(), packet->dwDataSize);
	}


	emit updateRetrieveBytesCount(packetRaw.size() + dataRaw.size());

	if (packet->_header.Command == _hello) 
	{
		emit HelloClient(this, packet);
	}
	else 
	{
		emit PacketReady(packet);
	}

}
示例#3
0
void ConnectionWidget::readPendingDatagrams()
{

    QByteArray datagram;
    QHostAddress sender;
    quint16 senderPort;

    while(udpSocket->hasPendingDatagrams())
    {
        //READ from Socket
        datagram.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    }

    QString text = QString("Recieved Size: ");

    text.append(QString::number(datagram.size()));
    statusNetworkLabel->setText(text);
    emit PacketReady(&datagram);
}