Last active
August 15, 2018 19:02
-
-
Save thomasballinger/5cc8485d07073d3d36d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import select | |
import sys | |
clients = [] | |
server = socket.socket() | |
server.bind(('', 8001)) | |
server.listen(1) | |
while True: | |
rs, ws, es = select.select([server] + clients + [sys.stdin], [], [], 10) | |
for reader in rs: | |
if reader is server: | |
client, (ip, port) = server.accept() | |
clients.append(client) | |
else: | |
data = client.recv(1000) | |
for recipient in clients: | |
recipient.send(data) | |
if not rs: | |
print 'no activity for 10 seconds' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment