Python Socket Backlog
#Below, you see a python program that acts as a server listening for connection requests to port 9999:
# server.py
import socket
import time
# create a socket object
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = socket.gethostname()
port = 9999
# bind to the port
serversocket.bind((host, port))
# queue up to 5 requests
serversocket.listen(5)
while True:
# establish a connection
clientsocket,addr = serversocket.accept()
print("Got a connection from %s" % str(addr))
currentTime = time.ctime(time.time()) + "
"
clientsocket.send(currentTime.encode('ascii'))
clientsocket.close()
#The questions is what is the function of the parameter of socket.listen() method (i.e. 5).
#Based on the tutorials around the internet:
#The backlog argument specifies the maximum number of queued connections and should be at least 0; the maximum value is system-dependent (usually 5), the minimum value is forced to 0.
Imaginathan