I just need some clarification about how works onSend and onReceive.
I send data from a client to a server with my class inherited from sf::Packet. I have overloaded sf::Packet::operator<< / operator>>
like below :
Class A, inherited from Packet
class A : public sf::Packet {
public:
(...)
protected:
sf::Packet& operator<<(sf::Packet& packet, A& a){
(...)
packet << a.name;
return packet;
}
sf::Packet& operator>>(sf::Packet& packet, A& a){
(...)
return packet;
}
/*
Data encryption
*/
const void* onSend(std::size_t& size)
{
const void* srcData = getData();
std::size_t srcSize = getDataSize();
size = srcSize;
return this->c.encryption(srcData, srcSize, size);
//return nullptr;
}
void onReceive(const void* data, std::size_t size)
{
std::cout << "Hello" << std::endl;
}
};
Then where data are sent :
sf::TcpSocket socket;
sf::Socket::Status status = socket.connect(dest, port);
while(!f.endFragmentation()){
int instruction = (f.lastFragment()) ? 1 : 0;
sf::Packet paquet;
paquet << instruction << f;
if (status != sf::Socket::Done)
{
}
if (socket.send(paquet) != sf::Socket::Done)
{
}
}
Problem is whatever I write into onSend or onReceive, my data are always nicely received.
Yes I know, it sounds good but I would like the data to be encrypted
So, I tried to return encrypted data, then nullptr and it never changed something. It seems like A::onSend/onReceive are never called.
Do you see what I'm doing wrong ?
I take advantage of this post to ask you an information about onReceive, in the SFML tutorial about sf::Packet, it's writed :
virtual void onReceive(const void* data, std::size_t size)
{
std::size_t dstSize;
const void* dstData = uncompressTheData(data, size, &dstSize); // this is a fake function, of course :)
append(dstData, dstSize);
}
If the goal is to uncompress data, why append them to the data already existing ? It shouldn't be better to replace old data by the new ?