Skip to content

Instantly share code, notes, and snippets.

@jizhang
Created January 18, 2015 06:28
Show Gist options
  • Save jizhang/0cd128d97a2f8862eba3 to your computer and use it in GitHub Desktop.
Save jizhang/0cd128d97a2f8862eba3 to your computer and use it in GitHub Desktop.
simple word stream
import SocketServer
import random
import time
words = ('cat', 'dog', 'monkey', 'horse', 'rabbit')
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
while True:
self.request.sendall(' '.join(random.sample(words, 3)) + '\n')
time.sleep(0.1)
if __name__ == '__main__':
server = SocketServer.TCPServer(('127.0.0.1', 9999), MyTCPHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment