title: Why my network TCP/UDP implementation isn't working?
body: <p>I want to have a server that </p>
  
  <ul>
  <li><p>Can send and receive TCP messages.</p></li>
  <li><p>Can send and receive UDP messages.</p></li>
  </ul>
  
  <p>multiple clients that</p>
  
  <ul>
  <li>Can send and receive TCP messages</li>
  <li>Can send and receive UDP messages.</li>
  </ul>
  
  <p>I use basic sockets and <code>select</code> for my server and the network SFML module for the client side (<a href="http://www.sfml-dev.org/tutorials/2.4/network-socket.php" rel="nofollow noreferrer">http://www.sfml-dev.org/tutorials/2.4/network-socket.php</a>).</p>
  
  <p>On the server side I create my socket, bind the TCP and UDP port to 4005.</p>
  
  <p>On the client side I use the <code>connect(host, ip)</code> call for TCP, and I bind the UDP port to 4006, as my UDP port is already binded to 4005 on the server side.</p>
  
  <p><strong>At the moment, my TCP is working fine, I can send a receive a message on both sides(client and server).</strong></p>
  
  <p>I am trying to send a UDP packet from server to client. To do so, I am taking the sockaddr_in from the accepted client socket I want to send a message(the sockaddr_in filled by the <code>accept</code> function). </p>
  
  <p><strong>But when I send it, my client doesn't receive it.</strong> </p>
  
  <p>I send it this way : </p>
  
  <pre><code>unsigned int UDPSocket::send(Message &amp;buffer, sockaddr_in const &amp;addr)
  {
    sockaddr_in cpy;
  
    std::memcpy(&amp;cpy, &amp;addr, sizeof(sockaddr_in));
    //return ::send(_sock, buffer.getData().data(), buffer.getData().size(), 0);
    std::cout &lt;&lt; "sending to " &lt;&lt; buffer.getClientId() &lt;&lt; std::endl;
    int fromsize = sizeof(sockaddr_in);
    cpy.sin_port = htons(4005 +1);
    std::cout &lt;&lt; "sending to " &lt;&lt; 4005 + 1 &lt;&lt; std::endl;
    int ret = ::sendto(_sock, buffer.getMessage(), buffer.getSize(), 0, (struct sockaddr *) &amp;cpy, fromsize);
    perror("sendto");
    std::cout &lt;&lt; ret &lt;&lt; std::endl;
    return ret;
  }
  </code></pre>
  
  <p>ret is superior to 0 and <code>perror</code> return success, so the message should be sended.</p>
  
  <p>I receive it this way : </p>
  
  <pre><code>bool              Network::updateQueueUDP()
  {
    unsigned char   data[sizeof(Protocol::rtypePacket)];
    bool            ret = false;
    std::size_t     received;
    sf::IpAddress   sender;
    unsigned short  senderPort;
  
    if (_udpSocket.receive(data, sizeof(data), received, sender, senderPort) == sf::Socket::Done)
    {
      Message *msg = new Message();
      msg-&gt;setMessage(data, received, 0);
      _udpQueue.push(msg);
      std::cout &lt;&lt; "pushing" &lt;&lt; std::endl;
      ret = true;
    }
    return ret;
  }
  </code></pre>
  
  <p>But <code>receive</code> never returns <code>sf::Socket::Done</code></p>
  
  <p>Do you have an idea why I don't receive anything in the UDP of my client ? </p>