In this section, you will learn about socket programming with non-blocking socket I/O.
Non-blocking and asynchronous socket I/O
Introducing non-blocking I/O
First, we are going to review a simple example of non-blocking I/O for the socket server. This script will run a socket server and listen in a non-blocking style. This means that you can connect more clients who won't be necessarily blocked for I/O.
You can find the following code in the server_socket_async.py file:
#!/usr/bin/env python3
import socket
if __name__ == '__main__':
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#unset blocking
sock.setblocking(0)
sock.settimeout(0.5)
sock.bind(("127.0.0.1", 12345))
socket_address...