What do you mean by "corrupts the packets"? If you mean data corruption, how do you determine this? Did you check whether this corresponds to what the server is sending?
As for the receive not working, it might also be the client code that is not sending/functioning properly. If you want to make robust software that functions even over bad connections, you need to make sure that both sides are able to handle such a scenario.
Maybe you could show the client send and receive code as well.
Ok. Here is the client receive code (it is multi threaded and blocking still since I haven't had any problems with it).
while(running)
{
while(gl::Vars::connected)
{
sf::Packet pack;
socket.receive(pack);
gl::mutex.lock();
sf::Int32 packetType; // Determines what the packet contains, different packet types contain different info
if(pack >> packetType)
{
/*
HANDLE PACKETS
*/
}
else
{
std::cout << "Junk Packet";
}
gl::mutex.unlock();
sf::sleep(sf::milliseconds(10));
}
sf::sleep(sf::seconds(.1));
}
}
I really don't think this is a client sided issue since it was receiving the packets correctly before I changed it all around.
By the way, I also simplified the server sends:
void Connector::sendPacket(sf::Packet* spack)
{
if(packets.size() <= 0)
{
sf::Socket::Status status = socket.send(*spack);
if(status == sf::Socket::NotReady)
{
packets.push(*spack);
}
}
else
{
packets.push(*spack);
}
}
void NetworkManager::retryDroppedPackets()
{
for(sf::Int32 i = 0; i < ent::connectors.size(); i++)
{
if(ent::connectors[i]->packets.size() > 0)
{
sf::Socket::Status status = ent::connectors[i]->socket.send(ent::connectors[i]->packets.front());
if(status != sf::Socket::NotReady)
{
ent::connectors[i]->packets.pop();
}
}
}
}