Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Last active Aug 15, 2018
Embed
What would you like to do?
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