title: SFML TCP packet receive
body: <p>I send a packet as client to server and I want to the server sends that packet forward to all client, here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;SFML/Network.hpp&gt;
  using namespace std;
  int main()
  {
  int fromID; // receive data from 'fromID'
  int Message; // fromID's message
  
  sf::SocketTCP Listener;
  if (!Listener.Listen(4567))
      return 1;
  // Create a selector for handling several sockets (the listener + the socket associated to each client)
  sf::SelectorTCP Selector;
  
  Selector.Add(Listener);
  
  while (true)
  {
      unsigned int NbSockets = Selector.Wait();
      for (unsigned int i = 0; i &lt; NbSockets; ++i)
      {
          // Get the current socket
          sf::SocketTCP Socket = Selector.GetSocketReady(i);
  
          if (Socket == Listener)
          {
          // If the listening socket is ready, it means that we can accept a new connection
              sf::IPAddress Address;
              sf::SocketTCP Client;
              Listener.Accept(Client, &amp;Address);
              cout &lt;&lt; "Client connected ! (" &lt;&lt; Address &lt;&lt; ")" &lt;&lt; endl;
  
              // Add it to the selector
              Selector.Add(Client);
          }
          else
          {
              // Else, it is a client socket so we can read the data he sent
              sf::Packet Packet;
              if (Socket.Receive(Packet) == sf::Socket::Done)
              {
  
                 // Extract the message and display it
                  Packet &gt;&gt; Message;
                  Packet &gt;&gt; fromID;
                  cout &lt;&lt; Message &lt;&lt; " From: " &lt;&lt; fromID &lt;&lt; endl;
  
                  //send the message to all clients
                  for(unsigned int j = 0; j &lt; NbSockets; ++j)
                  {
                      sf::SocketTCP Socket2 = Selector.GetSocketReady(j);
  
                      sf::Packet SendPacket;
                      SendPacket &lt;&lt; Message;
                      if(Socket2.Send(SendPacket) != sf::Socket::Done)
                          cout &lt;&lt; "Error sending message to all clients" &lt;&lt; endl;
                  }
              }
              else
              {
                // Error : we'd better remove the socket from the selector
                  Selector.Remove(Socket);
              }
          }
      }
  }
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>Client code:
  in Player class I have this function :</p>
  
  <pre><code>void Player::ReceiveData()
  {
   int mess;
   sf::Packet Packet;
   if(Client.Receive(Packet) == sf::Socket::Done)
   {
      Client.Receive(Packet);
      Packet &gt;&gt; mess;
      cout &lt;&lt; mess &lt;&lt; endl;
   }
  }
  </code></pre>
  
  <p>main.cpp: </p>
  
  <pre><code>Player player;
  player.Initialize();
  player.LoadContent();
  player.Connect();
  ..
  ..
  //GAME LOOP
  while(running==true)
  {
     sf::Event Event;
     while(..) // EVENT LOOP
     {
     ...
     }
     player.Update(Window);
     player.ReceiveData();
     player.Draw(Window);
  }
  </code></pre>
  
  <p>When I run this client code, the program not responding, freezes.
  The problem is with that ReceiveDate() function.</p>