title: Streaming on UDP
body: <p>I have the following issue here: I want to write a server streaming data on a UDP socket on a specific port, and clients should be able to connect to it and receive the data that is being sent out without too much hassle: they just connect, and from the moment they start they should get data using <code>recvfrom</code> from the server.</p>
  
  <p>I have some problems with setting up the network related parts. So, here is a rough piece of code that I try to make work:</p>
  
  <pre><code>int udpSock = socket(AF_INET, SOCK_DGRAM, 0);
  if(udpSock == -1)
  {
      perror("Could not create audio output socket");
      exit(1);
  }
  
  struct sockaddr_in *sin = (struct sockaddr_in*)&amp;gOutgoingAddr;
  sin-&gt;sin_port = htons(40200);
  if(bind(udpSock, (const sockaddr*)sin, sizeof(struct sockaddr_in)) == -1)
  {
      perror("Cannot bind audio socket");
      exit(1);
  }
  
  int buffer_size = 0;
  char* data = get_next_buffer(&amp;buffer_size);
  while(buffer_size &gt; 0)
  {
      if(sendto(udpSock, (const void*)(data), buffer_size, 0, NULL, 0) == -1)
      {
          perror("sendto failure");
      }
      data = get_next_buffer(&amp;buffer_size);
  }
  </code></pre>
  
  <p>Do not worry about the gOutgoingAddr variable, it is obtained correctly using <code>getifaddrs</code>, it is valid. I am troubled regarding the parametrization of the <code>sendto</code> method, becasue right now the output of the application is: </p>
  
  <pre><code>sendto failure: Destination address required
  </code></pre>
  
  <p>That's true, because I don't have a destination address, since all the examples I have found till now show when the server gets a client connection, and there is the address. But since I don't have a client yet connected, I'd still want to stream out. </p>
  
  <p>I appreciate all help, I have no idea what Ishould put for the parameters of sendto:</p>
  
  <ol>
  <li>The gOutgoingAddress which is the address where I create the socket? I have tried this, but if I use the <code>tcpdump</code> linux command on the specified port, I get nothing.</li>
  <li>Should I create a multicast socket? This somehow makes no sense...</li>
  <li>Something else?</li>
  </ol>
  
  <p>Thanks,
  frc</p>