ryuzakinho
ryuzakinho

Reputation: 1919

Python - How to check whether a TCP server is already serving a client

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.

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.

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.

I am using something like the snippet below. The call to connect succeeds even when the server is serving another client.

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

Upvotes: 1

Views: 282

Answers (0)

Related Questions