You can refer the following sites: https://www.geeksforgeeks.org/socket-programming-multi-threading-python/?ref=rp https://www.geeksforgeeks.org/socket-programming-in-cc-handling-multiple-clients-on-server-without-multi-threading/ https://www.geeksforgeeks.org/socket-programming-python/ https://www.geeksforgeeks.org/multithreading-python-set-1/ https://youtu.be/Iu8_IpztiOU https://realpython.com/python-sockets/#running-the-multi-connection-client-and-server
For timeout feature https://stackoverflow.com/questions/15195167/how-to-properly-use-timeout-parameter-in-select
Other useful references https://stackoverflow.com/questions/230751/how-to-flush-output-of-print-function https://stackoverflow.com/questions/7127075/what-exactly-is-pythons-file-flush-doing