How to make socket.listen(1) work for some time and then continue rest of code???
- by Rami Jarrar
I'm making server that make a tcp socket and work over port range, with each port it will listen on that port for some time, then continue the rest of the code.
like this::
import socket
sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sck.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
msg =''
ports = [x for x in xrange(4000)]
while True:
try:
for i in ports:
sck.bind(('',i))
## sck.listen(1)
## make it just for some time and then continue this
## if there a connection do this
conn, addr = sck.accept()
msg = conn.recv(2048)
## do something
##if no connection continue the for loop
conn.close()
except KeyboardInterrupt:
exit()
so how i could make sck.listen(1) work just for some time ??