test-brondsem Wiki
Status: Inactive
Brought to you by:
brondsem
import socket
host = 'localhost' # empty string to listen on all interfaces, or 'localhost', or an external IP/hostname
port = 12345
listener = socket.socket()
listener.bind((host, port))
listener.listen(4) # the number of connections to queue. You often can't raise this higher than 5
while True:
try:
conn, addr = listener.accept()
buffer = conn.recv(4092) # maximum size to receive, in bytes
conn.close()
except IOError:
# if it times out (receives no data), we want it to just try again next time
pass
if buffer:
pass
# you'll probably want to put something here
listener.close() # clean it up when we're finished