I'm creating a python script that listens on several ports (defined in the portslist) and when someone connects to any of these ports, a "hello" message will be sent to them. Currently, the code below creates sockets for all ports in the portlist but only sends message to communication on last port.
Thanks
servers = []
for port in portlist:
datasocket = ("0.0.0.0", port)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(datasocket)
server.listen(5)
servers.append(server)
while True:
ready_server = select.select(servers, [], [])
for s in ready_server:
connection, address = server.accept()
print str(address) + " has connected!\n"
msg ="hello\n"
connection.send(msg)
connection.close()
whileloop