Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Last active August 15, 2018 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasballinger/5cc8485d07073d3d36d2 to your computer and use it in GitHub Desktop.
Save thomasballinger/5cc8485d07073d3d36d2 to your computer and use it in GitHub Desktop.
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