Hello guys! I have a problem with a client: if I only use both socket.send and socket.receive like here:
socket.setBlocking(false);
sf::RenderWindow window(sf::VideoMode(800, 600), "Game");
while(window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
packet << "action" << me.name << "right";
status=socket.send(packet, serverIP, serverPort);
packet.clear();
}
socket.receive(packet, serverIP, serverPort);
if(packet.getDataSize()>0)
{
packet >> type_receive;
if(type_receive=="movement_x")
{
packet >> name >> x;
packet.clear();
std::cout << name << "\t" << x << std::endl;
}
}
window.clear(sf::Color::Black);
window.display();
}
The programme doesn't send nor receive. If I delete the socket.receive part like here:
socket.setBlocking(false);
sf::RenderWindow window(sf::VideoMode(800, 600), "Game");
while(window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
packet << "action" << me.name << "right";
status=socket.send(packet, serverIP, serverPort);
packet.clear();
}
window.clear(sf::Color::Black);
window.display();
}
The programme works. Do you know why is that? I tried almost everything