title: Socket programming for Python 2.7.10 with PyPy 5.1.2: Flush -- send data immediately
body: <p>I have a server and many client implemented in Python, talking over sockets. I want message sent from both sides to be rushed immediately to the other side.</p>
  
  <p>I found <a href="https://bytes.com/topic/python/answers/790818-socket-flushing" rel="nofollow noreferrer">this</a> article which talks about calling <code>.flush()</code> on the socket. However, I don't see any <code>flush()</code> api in the <em>python</em> doc <a href="https://docs.python.org/2/library/socket.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p><a href="https://stackoverflow.com/questions/4407835/python-socket-flush">Here</a> is a stackoverflow answer regarding the similar question. </p>
  
  <ul>
  <li>It suggests a naive option of closing the socket. However, I want to keep one connection and not re-connect again and again(to avoid complexity of code and useless burden on system.)</li>
  <li>It has another answer suggesting to convert the socket to a textfile like object and then call <code>flush</code> on it. However, comments there raise question on its credibility and it is for python 3 and is not accepted answer as well.</li>
  </ul>
  
  <p>I do NOT necessarily need TCP socket, UDP is fine for me as well. But the only thing I want is that data should be sent immediately. Any suggestions for achieving that? I would prefer clean solution, however, hacks are welcome as well.</p>