I don't know what is wrong but the fist time it sends the coordinates
it recieves but the second time it just waits forever
I don't get it
this is my code
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <iostream>
#include <SFML/Network.hpp>
using namespace std;
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
int x=5,y=5;
string choose;
cout << "recieve or send:";
cin >> choose;
cout << endl;
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
// A key has been pressed
if (Event.Type == sf::Event::KeyPressed)
{
// Escape key : exit
if (Event.Key.Code == sf::Key::Escape)
App.Close();
}
}
if(choose == "s"){
x=10;
y=10;
//networking part
// Create the UDP socket
sf::SocketUDP Socket;
sf::Packet send;
send << x << y;
cout << "send: "<< x << y <<endl;
// Send data to "192.168.0.2" on port 4567
if (Socket.Send(send, "127.0.0.1", 4567) != sf::Socket::Done)
{
cout << "error" << endl;
}
}else{
// Create the UDP socket
sf::SocketUDP Socket;
// Bind it (listen) to the port 4567
if (!Socket.Bind(4567))
{
// Error...
}
cout << "no error1" << endl;
sf::Packet recieved;
std::size_t r;
sf::IPAddress ClientAddress;
unsigned short ClientPort;
cout << "no error2" << endl;
if (Socket.Receive(recieved, ClientAddress,ClientPort) != sf::Socket::Done)
{
cout << "error somthing failes" << endl;
}
cout << "no error3" << endl;
recieved >> x >> y;
cout << "recieved :" << x << " " << y << endl;
}
// Clear the screen with red color
App.Clear();
App.Draw(sf::Shape::Rectangle(x,y,x+32,y+32,sf::Color::Red));
// Display window contents on screen
App.Display();
}
return EXIT_SUCCESS;
}
Ist in a infinite loop so it must work
Thanks