March 2019
Beginner
490 pages
12h 40m
English
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 python3import socketif __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 =sock.getsockname() print("Asynchronous socket server launched on socket: %s" %str(socket_address)) while(1): sock.listen(1)
From a client point of view, when we make a socket non-blocking ...
Read now
Unlock full access