Skip to content

Instantly share code, notes, and snippets.

@pcostesi
Created April 13, 2014 17:03
Show Gist options
  • Save pcostesi/10592738 to your computer and use it in GitHub Desktop.
Save pcostesi/10592738 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
from select import select
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# sock.bind((socket.gethostname(), 1234))
sock.bind(('', 1234))
sock.listen(5)
clients = [sock]
while True:
readables, writables, exeptionals = select(clients, [], [], 1)
print readables, writables, exeptionals
if not readables and not writables and not exeptionals:
print "tick"
for readable in readables:
if readable == sock:
clients.append(sock.accept()[0])
else:
print readable.recv(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment