title: Python - How to check whether a TCP server is already serving a client
body: <p>I am using the Kaldi speech recognition toolkit's "online 2-tcp-nnet3-decode-faster". The server receives raw audio and sends the text corresponding to this audio live. In other words, when using such a server, the idea is to start transcribing audio as soon as it is sent.</p>
  
  <p>If the server is busy serving one client request, it cannot handle a second one. The second request will remain idle until the first transcription completes and the first client closes the connexion.</p>
  
  <p>I would like to build a python client to communicate with the TCP server via websockets. I am able to create a socket connexion, however, I am still not able to determine whether the server is already serving another client so that I can try other servers on other ports or, create a new server instance on the fly.</p>
  
  <p>I am using something like the snippet below. The call to connect succeeds even when the server is serving another client.</p>
  
  <pre><code>import socket
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.connect((HOST, PORT))
  </code></pre>