title: UDP socket server with poll() in C
body: <p>I'm trying to code in C the UDP server that would use <code>poll()</code> (in non-blocking way but lets skip this for the moment) to communicate with multiple clients. I hardly grasp the basic concept of the flow scheme here (many examples of how to use poll with TCP can be found but couldn't find anything enlightening for UDP/poll).</p>
  
  <p>So my understanding is as follows: I have an array </p>
  
  <pre><code>struct pollfd poll_set[N];
  </code></pre>
  
  <p>initialize it </p>
  
  <pre><code>for (i = 0; i &lt; MAX_NUMBER_OF_CLIENTS; ++i) {
         poll_set[i].fd = -1;
         poll_set[i].events = POLLIN;
         poll_set[i].revents = 0;
  }
  </code></pre>
  
  <p>now I suppose I should create a socket or sockets and bind it/them. So at least </p>
  
  <pre><code>poll_set[0].fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (poll_set[0].fd &lt; 0)
      err(...);
  if (bind(poll_set[0].fd,...) &lt; 0)
      err(...);
  </code></pre>
  
  <p>and in endless loop I do the job checking for events:</p>
  
  <pre><code>for (;;) { 
      poll_ret = poll(poll_set, N, TIMEOUT);
      if (poll_ret &gt; 0)
          "find element of poll_set[] where event occured and read from it"
  }
  </code></pre>
  
  <p>but when and how do I create sockets/bind the elements <code>poll_set[i]</code> for <code>i = 1 .. N-1</code>? </p>