title: Are select()/poll() appropriate methods for a simple real time game server in C?
body: <p>I'm working on a simple multiplayer online text game and I read <code>select()</code> and <code>poll()</code> were popular methods for multiplexing I/O.</p>
  
  <p>I found this <a href="http://www.gnu.org/software/libc/manual/html_node/Server-Example.html#Server-Example" rel="nofollow">example in the GNU C docs</a>, which uses <code>select</code>. I ran it and made 3 Python test clients that look like this:</p>
  
  <pre><code>import socket
  import time
  
  port = 5555
  test = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  test.connect(('localhost', port))
  
  while 1:
      test.send('aaaa')
      time.sleep(0.5)
  </code></pre>
  
  <p>Then I ran the clients (from the same computer that's running the server) with different strings (<code>aaaa</code>, <code>55</code> and <code>..</code>).</p>
  
  <p>The output of the server was</p>
  
  <pre><code>Server: got message: `aaaa'
  Server: got message: `55aa'
  Server: got message: `aaaa'
  Server: got message: `55aa'
  Server: got message: `..aa'
  </code></pre>
  
  <p>The strings were getting mixed up.</p>
  
  <p>Is this some kind of silly compilation error, an error in my test clients or the fact that I'm running clients and servers from the same computer? Or is this program telling me I shouldn't use <code>select</code> for this purpose? Considering that I'll use this for a multiplayer game server (which probably gets lots of messages per second), I don't think I can let the messages get mixed up.</p>