server.setblocking(0), that is used to make the socket nonblocking.
select.selectto ask the OS to check given sockets whether they are ready to read, write or if there is any exception. That is why we pass the list of inputs, outputs and inputs again, so that each one respectively is checked if they are ready for the given operation.
sthat is in the list of the readable ones:
acceptthe connection, set it as non-blocking, append it to the
inputsand adds a
Queuefor incoming messages which will be sent back.
recvit. In case there is no data it means that the connection was closed, so we remove it from the outputs and then close the socket, deleting the message_queues. If there is data, it simply appends the data to the message queues.