I have these 2 functions, I want server A to send a data packet to client B.
void A()
{
sf::TcpSocket socket;
sf::Packet packet;
int test1 = 1;
float test2 = 1.0f;
double test3 = 1.111;
packet << test1 << test2 << test3;
socket.send(packet);
}
void B()
{
sf::Packet packet;
sf::TcpSocket socket;
socket.receive(packet);
int test1;
float test2;
double test3;
packet >> test1 >> test2 >> test3;
if (packet >> test1 >> test2 >> test3)
{
cout << test1 <<" " << test2 << " " << test3 << endl;
}
else
{
cout << "Failed" << endl;
}
}
Anything wrong with my code? When I test the program, "Failed" is always displayed instead of working correctly.